【发布时间】:2012-07-26 04:43:14
【问题描述】:
下面的代码几乎与 Douglas Crockford 的名著 JavaScript:The Good Parts(第 29-30 页)中的一些代码相同。唯一的区别是他像这样添加了 get_status 属性:
Quo.prototype.get_status=function() {
this.status=string;
}
我的问题是为什么他的代码运行正常,但我在下面的一点点改动导致了一个错误,提示 myQuo 没有 get_status 方法?
<script>
var Quo=function(string) {
this.status=string;
}
Quo.get_status=function() {
return this.status;
}
var myQuo=new Quo("confused");
alert(myQuo.get_status());
</script>
【问题讨论】:
标签: javascript function-prototypes