JSB 下的深拷贝
来源:互联网 发布:php怎么读 编辑:程序博客网 时间:2024/06/05 05:32
在JSB环境下,h5模式的cc.clone是使用不了。
解决方案:
将 cc.clone 拷贝到 jsb_prepare.js
cc.clone = function (obj) { // Cloning is better if the new object is having the same prototype chain // as the copied obj (or otherwise, the cloned object is certainly going to // have a different hidden class). Play with C1/C2 of the // PerformanceVirtualMachineTests suite to see how this makes an impact // under extreme conditions. // // Object.create(Object.getPrototypeOf(obj)) doesn't work well because the // prototype lacks a link to the constructor (Carakan, V8) so the new // object wouldn't have the hidden class that's associated with the // constructor (also, for whatever reasons, utilizing // Object.create(Object.getPrototypeOf(obj)) + Object.defineProperty is even // slower than the original in V8). Therefore, we call the constructor, but // there is a big caveat - it is possible that the this.init() in the // constructor would throw with no argument. It is also possible that a // derived class forgets to set "constructor" on the prototype. We ignore // these possibities for and the ultimate solution is a standardized // Object.clone(<object>). var newObj = (obj.constructor) ? new obj.constructor : {}; // Assuming that the constuctor above initialized all properies on obj, the // following keyed assignments won't turn newObj into dictionary mode // because they're not *appending new properties* but *assigning existing // ones* (note that appending indexed properties is another story). See // CCClass.js for a link to the devils when the assumption fails. for (var key in obj) { var copy = obj[key]; // Beware that typeof null == "object" ! if (((typeof copy) === "object") && copy && !(copy instanceof cc.Node)) { newObj[key] = cc.clone(copy); } else { newObj[key] = copy; } } return newObj;};
0 0
- JSB 下的深拷贝
- Helper::seekWidgetByName 在JSB环境下的优化
- ios下的深拷贝和浅拷贝概念
- Ext JS的文件夹下没有一个叫ext.jsb的文件的解决办法
- C++下深拷贝和浅拷贝 .
- cocos2d-html5 和 cocos2d-jsb的区别
- linux 下的光盘拷贝
- linux下的远程拷贝
- linux下的文件拷贝
- Objective-c下的深拷贝、浅拷贝以及NSCopying协议
- 讲述下C++下深拷贝和浅拷贝
- 讲述下C++下深拷贝和浅拷贝
- c++中 拷贝构造函数的深拷贝和浅拷贝--“浅拷贝”与“深拷贝”
- 浅拷贝与深拷贝、以及深拷贝的实现
- C++的拷贝构造函数(深拷贝、浅拷贝)
- Map拷贝 关于对象深拷贝 浅拷贝的问题
- Python对象的拷贝,浅拷贝和深拷贝。
- Map拷贝 关于对象深拷贝 浅拷贝的问题
- 软件中模块的理解
- 今天开始学习python
- oracle 常见问题处理
- App打造自定义的统计SDK, 是时候和友盟说分手了
- python学习日志
- JSB 下的深拷贝
- 从PHP获取一个数组,添加到页面的下拉选择框
- shape的使用
- spring 中如何读取properties的中属性信息
- 使用SAX解析简单的XML数据
- Java提高篇(八):实现多重继承
- Linux系统编程文件IO
- Android之Activity的四种启动模式
- 代码整洁之道