方法
定义方法
方法就是把函数放在对象的里面,对象只有两个东西:属性和方法
var yang={ name:'杨不悔', birth:2000, age:function (){ //今年 - 出生的年 var now = new Date().getFullYear(); return now-this.birth; } } //属性 yang.name; //方法,一定要带() yang.age();
function getAge(){ var now = new Date().getFullYear(); return now-this.birth; } var y={ name:'杨不悔', birth:2000, age:getAge } //y.age(); ok //getAge() NaN window
apply
在js中可以控制this指向
function getAge(){ var now = new Date().getFullYear(); return now-this.birth; } var y={ name:'杨不悔', birth:2000, age:getAge } getAge.apply(y,[]);//this,指向了y,参数为空
我的一生
第1章-废物的一生
第50章-糟糕的婴儿
第300章-莫欺少年穷
第600章-莫欺中年穷
第1000章-莫欺老年穷
第1100章-不详的离去
第1101章-棺材板的震动
第1150章-盗墓贼的眼泪
第1200章-死者为大