gpt4 book ai didi

Javascript 错误 myfuntion.create 不是函数

转载 作者:行者123 更新时间:2023-12-02 19:44:07 25 4
gpt4 key购买 nike

直到我添加 jQuery 后才发生这种情况。

function mfunc() {}
mfunc.prototype.create = function(value) {
alert("hi");
}

结束正文标记之前的脚本:

$(document).ready(function(){
var mfunc = new mfunc();
alert("hi");
alert(mfunc.create("hello"));

});

我在 firebug 中收到以下错误:

mfunc.create is not a function

提前致谢。

最佳答案

您正在隐藏您的原型(prototype)函数!您的原始函数名为 mfunc,但随后您使用相同的变量名称来引用新实例。使用不同的变量名称:

$(document).ready(function(){
var mobj = new mfunc();
alert("hi");
alert(mobj.create("hello"));
});

关于Javascript 错误 myfuntion.create 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10065430/

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