gpt4 book ai didi

javascript - 'this' 在下面的 javascript 中代表什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:52:53 26 4
gpt4 key购买 nike

(抱歉,javascript 中的另一个this 问题。)

我有下面的代码,我想知道最后调用中的“this”代表什么——Window 还是 Bird?

var Bird = (function () {
Bird.name = 'Bird';

function Bird(name) {
this.name = name;
}

Bird.prototype.move = function (feet) {
return alert(this.name + (" flew" + feet + "ft."));
};

return Bird;

}).call(this);

最佳答案

好吧,假设没有父作用域,它是 window

编辑:参见示例:http://jsfiddle.net/Umseu/1

关于javascript - 'this' 在下面的 javascript 中代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10337368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com