Skip to content

Instantly share code, notes, and snippets.

@winwu
Created July 25, 2016 15:07
/* interfeace 定義對象內部結構 也可以用來約束 class 的行為*/
interface Employee {
jobTitle: string,
years?: number
};
// 此 function 接受 Employee 型別的變數 e
function getEmployeeBasicSalary(e: Employee) {
// 可能的底薪,亂 key 的 只是示範 XD
let basicSalary = e.years * 2;
alert(basicSalary);
}
const myManager = {
jobTitle: 'Project Manager',
years: 3
};
const mySelf = {
jobTitle: 'Frontend',
years: 5
};
getEmployeeBasicSalary(myManager); // alert 6
getEmployeeBasicSalary(mySelf); // alert 10
@winwu
Copy link
Author

winwu commented Jul 25, 2016

;
// 此 function 接受 Employee 型別的變數 e
function getEmployeeBasicSalary(e) {
    // 可能的底薪,亂 key 的 只是示範 XD
    var basicSalary = e.years * 2;
    alert(basicSalary);
}
var myManager = {
    jobTitle: 'Project Manager',
    years: 3
};
var mySelf = {
    jobTitle: 'Frontend',
    years: 5
};
getEmployeeBasicSalary(myManager); // alert 6
getEmployeeBasicSalary(mySelf); // alert 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment