Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attribute代码严重bug #22

Closed
lianqin7 opened this issue Jun 17, 2013 · 4 comments
Closed

attribute代码严重bug #22

lianqin7 opened this issue Jun 17, 2013 · 4 comments
Labels

Comments

@lianqin7
Copy link
Member

简单还原代码如下:

seajs.use('widget', function(Widget){
    var t = new Widget();
    t.set('parentNode', document.getElementById('show'));
    t.render();
});

IE8及以下报 对象不支持“hasOwnProperty”属性或方法

原因在这:https://github.com/aralejs/base/blob/master/src/attribute.js#L97

isEqual方法内部会最终调用到isEmptyObject,但是没有做isPlainObject的保护判断,所以报错( IE8及以下的原生dom没有hasOwnProperty

@lizzie
Copy link
Member

lizzie commented Jun 17, 2013

貌似是在实例化 widget 之后才 set parentNode 的问题, 把 parentNode 作为参数传入 Widget, 不会出现 "hasOwnProperty" 的报错.

@lizzie
Copy link
Member

lizzie commented Jun 17, 2013

set("parentNode", xx) 时, 比较的是 当前 parentNode 的值即 document.body 和 xx 是否相等. document.body.hasOwnProperty 却为 undefined ..

@lizzie lizzie closed this as completed in d6414e8 Jun 17, 2013
@lizzie
Copy link
Member

lizzie commented Jun 17, 2013

最终原因是:

isEmptyObject() 中 Object.prototype.toString.call(document.body) 在 <=IE8 下也为 "[object Object]" , 所以添加判断条件 o.nodeType || isWindow(o)

@popomore
Copy link
Member

之前一直没注意,这段逻辑在实例化的时候不会触发,只有调用 set 的时候才触发,所以使用 parentNode 的时候一直没问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants