将“this”传递给原型函数嵌套函数

Passing 'this' to prototype function nested function

提问人:Hello 提问时间:8/15/2022 最后编辑:Hello 更新时间:8/15/2022 访问量:36

问:

传递“this.dayNames”并在嵌套函数 (createCalendar()) 中使用它的最佳样式是什么?

function DateNames()
{
    this.dayNames = ["Su", "M", "T", "W", "Th", "F", "S"];
}

DateNames.prototype.render = function(date)
{
    console.log(date);
    createCalendar()
    function createCalendar()
    {
        console.log(this.dayNames);
    }
}
javascript 这个 原型

评论

3赞 evolutionxbox 8/15/2022
考虑删除内部功能?它没有被调用,它会更改绑定。this
1赞 evolutionxbox 8/15/2022
这回答了你的问题吗?“this”关键字是如何工作的,何时应该使用?
0赞 Hello 8/15/2022
@evolutionxbox,忘了补充一下,它实际上是被调用的。
0赞 evolutionxbox 8/15/2022
请考虑删除或使用箭头函数createCalendar

答: 暂无答案