Я получаю "TestFunc не определен" ошибка, когда этот бит кода ...Javascript: ошибка метода прототипа?
/* my_object.js */
"use strict";
function MyObject (param) {
this.param = param;
}
MyObject.prototype.TestFunc = function() {
console.log ('in TestFunc');
}
MyObject.prototype.RealFunc = function() {
// I have tried 3 different ways to call TestFunc:
// 1.
this.TestFunc();
// 2.
TestFunc();
// 3. (I didn't really think this would work,
// but thought it was worth a try...)
MyObject.TestFunc();
}
... получает бежать от этого бита кода:
/* index.js */
var myObj = new MyObject ('test');
myObj.RealFunc(); // Firebug: "TestFunc is not defined"
Я пробовал в firebug только с этим. TestFunc() 'и другие два закомментировали, он отлично работает. Попробуй еще раз. –