gpt4 book ai didi

javascript - 为什么在javascript中不调用函数对象中的函数包装

转载 作者:行者123 更新时间:2023-11-30 00:19:50 28 4
gpt4 key购买 nike

<分区>

我有 JavaScript 函数作为对象:

function hexMesh(){
var side=25;
console.log('hexMesh');

function drawOver(){
}
}

如您所见,它有一个函数调用 drawOver

我尝试使用构造函数调用它,如下所示:

window.onload = function() {
hexMeshObj=new hexMesh();
hexMeshObj.drawOver();
}

但它给了我错误提示说 undefined is not a function

现在我知道我可以在对象的原型(prototype)中声明函数,但我不想那样做。

这里是JSFiddle .

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