Javascript IE8,backbone.js中Object.toString的问题
IE8和对象的Javascript IE8,backbone.js中Object.toString的问题,javascript,internet-explorer-8,backbone.js,Javascript,Internet Explorer 8,Backbone.js,IE8和对象的toString方法是怎么回事 我试图在Backbone.js的模型中覆盖toString,但IE8似乎没有意识到该方法的存在。将方法名称更改为其他名称很好,但是为什么不能使用toString?这在Chrome中工作 var Foo = Backbone.Model.extend({ toString: function(){ return this.get("name"); }, description: function(){ return this.get("
toString
方法是怎么回事
我试图在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"
var Foo=Backbone.Model.extend({
toString:function(){返回this.get(“name”);},
描述:函数(){返回this.get(“name”);}
});
var f=新的Foo({name:“a Foo”});
document.writeln(f.toString());//“[对象]”,应为“一个foo”
书面文件(“
”);
document.writeln(f.description());//“阿福”
jsiddle code:如果您将
移动到主干.Model之外的字符串中。将扩展到:
Foo.prototype.toString=function(){返回this.get(“name”);}代码>
它起作用了。我怀疑主干正在做一些不符合IE8预期的时髦事情
编辑(感谢@Ferdinand Prantl):
传递到主干.extend中的所有属性都将使用for in
枚举添加到模型的原型中IE<9
有一个bug,它不会复制某些名为DontEnumBug的属性
在IE<9中,JScript将跳过任何对象中
对象的原型链中有一个相同的命名属性
具有DontEnum属性
构造函数、toString、valueOf、toLocaleString、prototype、isPrototypeOf、propertyIsEnumerable、hasOwnProperty、length和unique都将被跳过 主干图标通过枚举中的for从原型中复制所有属性。IE跳过名称为:构造函数、toString、ToLocalString、valueOf和isPrototypeOf的属性。它叫。