IE8和toString
对象的方法是什么?IE8中的Object.toString问题,backbone.js
我想在我的Backbone.js模型中覆盖toString
,但IE8似乎没有认识到该方法在那里。将方法名称更改为其他方法可以正常工作,但为什么我不能使用toString
?这适用于Chrome。
var Foo = Backbone.Model.extend({
toString: function(){ return this.get("name"); },
description: function(){ return this.get("name"); }
});
var f = new Foo({name: "a foo"});
document.writeln(f.toString()); // "[object Object]", should be "a foo"
document.writeln("<br/>");
document.writeln(f.description()); // "a foo"
的jsfiddle代码:http://jsfiddle.net/x96mR/3/
奇怪......我以为我尝试过,但显然不是。谢谢! – Sam
主干通过for-in枚举来覆盖原型的所有属性。 IE跳过名称的属性:构造函数,toString,toLocaleString,valueOf和isPrototypeOf。它被称为[DontEnumBug](https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug)。 –