// 函数可以作为对象的方法var obj = {name:"zhang",sayName:function(){console.log(this.name);}}// 在方法中,谁执行方法,this指向谁obj.sayName();
函数在对象中作为方法的语法(三种)
var obj = {name:"zheng",sayName(){console.log(this.name);},sayAge:()=>{console.log(18);},saySkill:function(){console.log("javascript");}}
var obj ={name:"html",sayName:function(){console.log(this.name)}}/* 函数是对象的一个方法 */obj.sayName();this关键字指向问题1、onclick 谁执行事件,this指向谁2、谁执行方法,this指向谁
