<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 原型鏈的問題
json = {
a : function(){
console.log('普通');
},
b(){
console.log('沒有冒號啊,大丈夫');
},
c : () =>{
console.log('箭頭函數啊,大丈夫');
}
}
// 曉調一下
json.a();
json.b();
json.c();
// Get Set
jsonSG = {
set setF(x){
console.log("這是Set "+x);
},
get getF(){
console.log("這是Get ");
}
// ,getF:1 // 這個也是錯的,不能有這種二義性的元素
// 會識別不出來,只能返回 undefined
,get getF1(){
return{
get getF11(){
console.log("這是Get 裏面的Get");
}
}
}
}
// 調用
// 如果不賦值 就會調用 get方法
jsonSG.getF;
// jsonSG.setF('123456'); // 這是錯誤的調用方法
// 如果賦值了,就會調用set方法
// 需要注意的是:
// 這個set只能賦值一個參數
// 並不能賦值複數個參數
jsonSG.setF = '1234567890' ;
// 調用
jsonSG.getF1.getF11;
</script>
</body>
</html>