调用方法的不同-对象文字

时间:2018-12-25 23:15:23

标签: javascript object-literal

let person = {  
    firstname: 'Rotten',  
    lastname: 'Apple',  
    greet: () => console.log(`Hello ${person.firstname} ${person.lastname}!`),

    greet2: function(){  
       console.log('Hello, ' + this.firstname);  
    }  
};

person.greet();
person.greet2();


为什么以上两个功能都起作用,而这两个功能却不起作用?

greet: () => console.log(`Hello ${this.firstname} ${this.lastname}!`)  

感谢您的回答

0 个答案:

没有答案