{"action":"opened","issue":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/16669","repository_url":"https://api.github.com/repos/cocos2d/cocos2d-x","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/16669/labels{/name}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/16669/comments","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/16669/events","html_url":"https://github.com/cocos2d/cocos2d-x/issues/16669","id":181961877,"number":16669,"title":"Missing cc.clone in JSB","user":{"login":"dumganhar","id":493372,"avatar_url":"https://avatars.githubusercontent.com/u/493372?v=3","gravatar_id":"","url":"https://api.github.com/users/dumganhar","html_url":"https://github.com/dumganhar","followers_url":"https://api.github.com/users/dumganhar/followers","following_url":"https://api.github.com/users/dumganhar/following{/other_user}","gists_url":"https://api.github.com/users/dumganhar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumganhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumganhar/subscriptions","organizations_url":"https://api.github.com/users/dumganhar/orgs","repos_url":"https://api.github.com/users/dumganhar/repos","events_url":"https://api.github.com/users/dumganhar/events{/privacy}","received_events_url":"https://api.github.com/users/dumganhar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"pandamicro","id":632460,"avatar_url":"https://avatars.githubusercontent.com/u/632460?v=3","gravatar_id":"","url":"https://api.github.com/users/pandamicro","html_url":"https://github.com/pandamicro","followers_url":"https://api.github.com/users/pandamicro/followers","following_url":"https://api.github.com/users/pandamicro/following{/other_user}","gists_url":"https://api.github.com/users/pandamicro/gists{/gist_id}","starred_url":"https://api.github.com/users/pandamicro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pandamicro/subscriptions","organizations_url":"https://api.github.com/users/pandamicro/orgs","repos_url":"https://api.github.com/users/pandamicro/repos","events_url":"https://api.github.com/users/pandamicro/events{/privacy}","received_events_url":"https://api.github.com/users/pandamicro/received_events","type":"User","site_admin":false},"assignees":[{"login":"pandamicro","id":632460,"avatar_url":"https://avatars.githubusercontent.com/u/632460?v=3","gravatar_id":"","url":"https://api.github.com/users/pandamicro","html_url":"https://github.com/pandamicro","followers_url":"https://api.github.com/users/pandamicro/followers","following_url":"https://api.github.com/users/pandamicro/following{/other_user}","gists_url":"https://api.github.com/users/pandamicro/gists{/gist_id}","starred_url":"https://api.github.com/users/pandamicro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pandamicro/subscriptions","organizations_url":"https://api.github.com/users/pandamicro/orgs","repos_url":"https://api.github.com/users/pandamicro/repos","events_url":"https://api.github.com/users/pandamicro/events{/privacy}","received_events_url":"https://api.github.com/users/pandamicro/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-10-10T08:39:28Z","updated_at":"2016-10-10T08:39:28Z","closed_at":null,"body":"cocos2d-html has an implementation of `cc.clone` like:\r\n\r\n```js\r\n/**\r\n * Create a new object and copy all properties in an exist object to the new object\r\n * @function\r\n * @param {object|Array} obj The source object\r\n * @return {Array|object} The created object\r\n */\r\ncc.clone = function (obj) {\r\n    // Cloning is better if the new object is having the same prototype chain\r\n    // as the copied obj (or otherwise, the cloned object is certainly going to\r\n    // have a different hidden class). Play with C1/C2 of the\r\n    // PerformanceVirtualMachineTests suite to see how this makes an impact\r\n    // under extreme conditions.\r\n    //\r\n    // Object.create(Object.getPrototypeOf(obj)) doesn't work well because the\r\n    // prototype lacks a link to the constructor (Carakan, V8) so the new\r\n    // object wouldn't have the hidden class that's associated with the\r\n    // constructor (also, for whatever reasons, utilizing\r\n    // Object.create(Object.getPrototypeOf(obj)) + Object.defineProperty is even\r\n    // slower than the original in V8). Therefore, we call the constructor, but\r\n    // there is a big caveat - it is possible that the this.init() in the\r\n    // constructor would throw with no argument. It is also possible that a\r\n    // derived class forgets to set \"constructor\" on the prototype. We ignore\r\n    // these possibities for and the ultimate solution is a standardized\r\n    // Object.clone(<object>).\r\n    var newObj = (obj.constructor) ? new obj.constructor : {};\r\n\r\n    // Assuming that the constuctor above initialized all properies on obj, the\r\n    // following keyed assignments won't turn newObj into dictionary mode\r\n    // because they're not *appending new properties* but *assigning existing\r\n    // ones* (note that appending indexed properties is another story). See\r\n    // CCClass.js for a link to the devils when the assumption fails.\r\n    for (var key in obj) {\r\n        var copy = obj[key];\r\n        // Beware that typeof null == \"object\" !\r\n        if (((typeof copy) === \"object\") && copy &&\r\n            !(copy instanceof cc.Node) && !(copy instanceof HTMLElement)) {\r\n            newObj[key] = cc.clone(copy);\r\n        } else {\r\n            newObj[key] = copy;\r\n        }\r\n    }\r\n    return newObj;\r\n};\r\n```\r\nBut it's missing in JSB.\r\n\r\n@pandamicro , could you please check this?"}}
{"actor":{"display_login":"dumganhar"}}