所以我想在函数A中调用函数B,但是函数B是在函数A之后完全声明的。我知道在c++中我们会在B上使用函数原型(prototype),但是javascript呢?
代码:
markerArray = function() {
// some code here
this.array = [];
this.clearArray = function() {
for(var i = 0; i<this.getLength(); i++)
// for loop code
}
this.getLength = function() {
return this.array.length;
}
// some code here
}
我把 this.getLength 放在下面的原因主要是因为这样我的编码风格/结构更具可读性
最佳答案
Javascript 不关心这个要求。只要在文件加载之后才调用函数 A,它就会正常工作。定义函数A,定义函数B,然后可以在函数A内部使用函数B调用函数A,没有问题。
关于javascript - C++ 函数原型(prototype)在 JavaScript 中等效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9335731/