JavaScript:Function.prototype

JavaScript:Function.prototype,javascript,Javascript,下面是从“好的部分”复制的一些代码,经过一些修改 program.html <html><body><pre><script src="program.js"> </script></pre></body></html> 错误 get\u status应为字符串。您试图传递一个变量,但函数接受字符串作为函数名 也许如果你解释了你想要实现的目标,或者提出了一个问题,你就不会得到反对票。 Functio

下面是从“好的部分”复制的一些代码,经过一些修改

program.html

<html><body><pre><script src="program.js">
</script></pre></body></html>
错误


get\u status
应为字符串。您试图传递一个变量,但函数接受字符串作为函数名


也许如果你解释了你想要实现的目标,或者提出了一个问题,你就不会得到反对票。
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

var Quo_2 = function (string) {
    this.status = string;
};

Quo_2.method(get_status, function () { return this.status; });

var myQuo_2 = new Quo_2("confused 2");

document.writeln(myQuo_2.get_status());
ReferenceError: get_status is not defined
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};

var Quo_2 = function (string) {
    this.status = string;
};
// added quotes around get_status
Quo_2.method('get_status', function () { return this.status; });

var myQuo_2 = new Quo_2("confused 2");

document.writeln(myQuo_2.get_status());