gpt4 book ai didi

javascript - Java脚本原型(prototype)中的方法未覆盖

转载 作者:行者123 更新时间:2023-11-30 08:31:53 25 4
gpt4 key购买 nike

<分区>


我刚刚阅读java script prototype programming,只是尝试了一小段代码。

function Ninja(){
this.swingSword = function(){
return true;
};
}

//override the prev one
Ninja.prototype.swingSword = function(){
return false;
};

var ninja = new Ninja();
console(ninja.swingSword());

但我认为这将是 false 的 OP,不幸的是它给出的输出为 true,我的第二种方法没有覆盖第一种方法。为什么?


只有 Ninja.prototype.swingSword() JsFiddle这给出了正确的覆盖......

那么在这里创建 object(ninja) 的目的是什么?

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