Javascript 为什么即使在I';我不叫它?
我只是想了解一下Javascript,发生了一件非常奇怪的事情。方法Javascript 为什么即使在I';我不叫它?,javascript,Javascript,我只是想了解一下Javascript,发生了一件非常奇怪的事情。方法getChapters()正在启动,尽管我没有显式地调用它……有什么想法吗?(我正在获取get章节的警报框) 删除new关键字: videoChapters.prototype.getChapters = function () { alert('getting chapters'); } 删除new关键字: videoChapters.prototype.getChapters = function () {
getChapters()
正在启动,尽管我没有显式地调用它……有什么想法吗?(我正在获取get章节的警报框)
删除
new
关键字:
videoChapters.prototype.getChapters = function () {
alert('getting chapters');
}
删除
new
关键字:
videoChapters.prototype.getChapters = function () {
alert('getting chapters');
}
这一行:
videoChapters.prototype.getChapters = new function () {
…可能不应包含“新”一词。当Javascript尝试计算表达式时,它会将函数的结果传递给“new”操作符。此行:
videoChapters.prototype.getChapters = new function () {
....prototype.getChapters = new function () {
^-------- See the new keyword here?
…可能不应包含“新”一词。当Javascript尝试计算表达式时,它会将函数的结果传递给“new”操作符
....prototype.getChapters = new function () {
^-------- See the new keyword here?
删除
new
关键字,一切都将按预期工作,使用new
将调用函数作为构造函数,并返回它的新实例,在本例中是匿名函数的新实例
删除
new
关键字,一切都将按预期工作,使用new
将调用函数作为构造函数,并返回它的新实例,在本例中是匿名函数的新实例