Created
July 25, 2016 15:07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
Author
winwu
commented
Jul 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment