带有箭头和匿名功能的此关键字

时间:2018-11-15 05:03:39

标签: javascript

下面是代码, 该代码可以正常工作 ,如果该函数是常用函数,但不能与箭头和匿名函数一起使用。但是我很感兴趣为什么在使用箭头和匿名功能的情况下无法正常工作。

var testObj={
    name:"Shivendra",
    age:22,
    summary:function(){
        console.log(`His name is ${this.name} and he is ${this.age} years old {Summary}`)
    },
    summary2: ()=>{
        console.log(`His name is ${this.name} and he is ${this.age} years old {Summary2}`)
    },
    summary3:function(){
        var nestedAnonymousFunction=function(){
            console.log(`His name is ${this.name} and he is ${this.age} years old{Summary3} `)
        }
        nestedAnonymousFunction();
    }
}

testObj.summary();
testObj.summary2();
testObj.summary3();

0 个答案:

没有答案