【发布时间】:2009-11-30 20:37:47
【问题描述】:
我正在尝试使用原型在 Object 对象中添加一个 toBool()“方法”...类似这样:
Object.prototype.toBool = function ()
{
switch(this.toLowerCase())
{
case "true": case "yes": case "1": return true;
case "false": case "no": case "0": case null: return false;
default: return Boolean(string);
}
}
var intAmount = 1;
if(intAmount.toBool())
但我在尝试从同一对象方法 this.toLowerCase() 中访问对象的值时遇到问题@
应该怎么做?
【问题讨论】:
标签: javascript prototype methods oop