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

KISSY1.4.2的merge方法串改了初始对象的prototype #575

Closed
ianli-sc opened this issue Mar 6, 2014 · 4 comments
Closed

KISSY1.4.2的merge方法串改了初始对象的prototype #575

ianli-sc opened this issue Mar 6, 2014 · 4 comments

Comments

@ianli-sc
Copy link

ianli-sc commented Mar 6, 2014

  • 在1.3.0版本我某个页面大量的使用了如下方法

    var a = S.one('#a1');
    var b = S.one('#a2');
    ...
    var list = [];
    list.push(S.merge(a, {
        _width: 30,
        _height: 40
        ...
    });
    ...
    S.each(list, function(item, index) {
        item.css('height', item._height);
    });
    ....
    
  • 当我升级到1.4.1的时候,item.css报错undefined。

  • 发现S.merge变成了向空对象内S.mix进入目标对象。而mix方法本身是不会修个prototype的,问题发生在使用空对象上

ianli-sc pushed a commit to ianli-sc/kissy that referenced this issue Mar 6, 2014
ianli-sc pushed a commit to ianli-sc/kissy that referenced this issue Mar 6, 2014
ianli-sc pushed a commit to ianli-sc/kissy that referenced this issue Mar 6, 2014
@ianli-sc ianli-sc mentioned this issue Mar 6, 2014
@yiminghe
Copy link
Member

yiminghe commented Mar 6, 2014

merge 参数必须是普通对象,不支持自定义对象,用于配置对象合并等用途,不是这么用的

@yiminghe yiminghe closed this as completed Mar 6, 2014
@ianli-sc
Copy link
Author

ianli-sc commented Mar 6, 2014

从文档中没有看出说是普通对象。
此外我不知道简单的对象合并是用什么方法。base?augment?看起来都不好。

@yiminghe
Copy link
Member

yiminghe commented Mar 6, 2014

S.mix(xx,{
// common object
})

@ianli-sc
Copy link
Author

ianli-sc commented Mar 6, 2014

  • mix会改变目标对象的属性。
  • 大约是我bug的描述偷懒了没写清楚。。。
  • 我的使用场景是:
    • 我有一个model层的对象,他继承了Base的Attribute,拥有attribute的方法。它的内部存储了页面初始化的数据。渲染页面。
    • 每次异步接口调用会传回部分数据的更新,为基本的object。
    • 我需要更新数据,进行合并,然后渲染页面。
    • 但是我必须保留初始化的数据,便于用户回滚。
    • 所以我不能修改model层的对象,而是生产一个新的合并后的对象。(不修改、进行合并、返回新对象,就KISSY文档而言,应当使用S.merge方法(在KISSY1.3.0版本时候是可以的)。
    • 在升级1.4.2后,merge方法改变了我的prototype,我再使用merge方法新生产的对象去渲染页面,调用内部方法时候,就会报错undefined
    • 因此我的issue和pull的意图就在于还原merge的本意:修改属性,产生新对象,不影响旧对象。

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

No branches or pull requests

2 participants