- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
也许你会发现问题所在。控制台总是显示:
类型错误:this._init 不是一个函数。 (在'this._init()'中,'this._init'未定义)
nodes = [];
for (var i = 0; i < 3; i++) {
var newNode = new Node(i*100,0);
nodes.push(newNode);
};
function Node(posX, posY, parent) {
if (typeof parent === 'undefined') { parent = 0; }
this.parent = parent;
this.children = [];
this.text = "Node";
this.posX = posX;
this.posY = posY;
this._init();
this._init = function() {
alert("test");
}
}
最佳答案
您需要在调用函数之前定义该函数:
function Node(posX, posY, parent) {
if (typeof parent === 'undefined') { parent = 0; }
this.parent = parent;
this.children = [];
this.text = "Node";
this.posX = posX;
this.posY = posY;
this._init = function() {
alert("test");
}
this._init();
}
如果您在其他地方定义函数之前调用了函数,您可能会对此感到困惑。在某些情况下,您的功能可能会被“提升”到脚本的顶部。下面展示了一个完全合法的调用:
isItHoisted();
function isItHoisted() {
console.log("Yes!");
}
http://adripofjavascript.com/blog/drips/variable-and-function-hoisting
您现在可能已经意识到,对象上的方法函数不会被提升,因此您会收到所看到的错误。
关于javascript - JS : TypeError: this. _init 不是函数。 (在 'this._init()' 中, 'this._init' 未定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31389129/
也许你会发现问题所在。控制台总是显示: 类型错误:this._init 不是一个函数。 (在'this._init()'中,'this._init'未定义) nodes = []; for (var
一些jquery插件扩展小部件使用_create方法,而另一些则使用_init方法,有人可以解释两者之间的区别吗? 还有关于何时扩展 widget 或直接扩展 jquery.fn 更好的指导吗? 最佳
我想知道这个子程序在 Perl 中做了什么。我相信我有大致的想法,但我想知道一些语法。 sub _init { my $self = shift; if (@_) { my %extr
在 x86 linux 上,进程 A.exe 调用 dlopen() 来加载共享库 B.so。在 B.so 中,有一个构造函数,它想知道进程 A.exe 中的哪个函数在调用 dlopen() 之前被中
出于观察目的,我使用 _start()、_init()、_fini() 编写了一个程序,目标是不使用启动文件。代码如下 #include void test() { printf("\n%s: \n
我正在创建一个共享库,我注意到使用 __attribute__((visibility("default"))) (连同 -fvisibility=hidden )我的图书馆也导出 _init和 _f
我认为在 tsocks 上做一些工作将是一个有趣的副项目,因为它已经 8 年没有看到任何更新了。它的托管here在 GitHub 上。 到目前为止,我只对代码进行了外观更改,但现在遇到了编译器错误。根
我正在构建一个共享库形式的调试内存工具,我在运行时链接到一个可执行文件(包括 malloc 系列的重写方法)。为了处理我的数据结构的初始化,我简单地使用了一个条件变量。每次调用我的 malloc 时,
让我们定义两个类 A.gd class_name A var v = null func _init(v_): v = v_ B.gd class_name B var v = null 现在
我想我理解小部件定义中 _create 和 _init 之间的区别(例如 this question ),但我仍然不确定 区分的目的。 _create() 或 _init() 中包含哪些类型的设置任务
C++ 新手。我想创建一个动态对象数组并使用 std::sort() 对它们进行排序。但是,出现了几个错误,我无法弄清楚原因。谢谢你的帮助。错误如下所示: > community\vc\tools\m
现在我在 linux 下编写一个可加载的 .so 模块,我想在主程序中使用 dlopen 并在可加载的 .so 模块中使用 _init()。我的程序是这样的: 主程序: ... dlopen(lib,
我不知道如何修复它,我搜索了太多信息,所有人都告诉我我没有安装 npm 模块,但我的 'package.json' 文件已经安装了它们。 我已经安装了所有的 npm 模块 dependencies":
我是linux新手,对于函数static int __init console_setup(char *str),它会返回int,函数名称是console_setup,但是这里的_init是什么意思?
我在玩 GDB 的 rbreak . 时首先注意到它,然后做了一个最小的例子: (gdb) file hello_world.out Reading symbols from hello_world.
我是一名优秀的程序员,十分优秀!