第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

沒有參考javascript的克隆對象

沒有參考javascript的克隆對象

動漫人物 2019-10-25 15:24:03
我有一個擁有大量數(shù)據(jù)的大物體。我想將其克隆到其他變量中。當我設置實例B的某些參數(shù)時,在原始對象中具有相同的結果:var obj = {a: 25, b: 50, c: 75};var A = obj;var B = obj;A.a = 30;B.a = 40;alert(obj.a + " " + A.a + " " + B.a); // 40 40 40我的輸出應該是25 3040。有什么想法嗎?編輯感謝大家。我更改了dystroy的代碼,這是我的結果:Object.prototype.clone = Array.prototype.clone = function(){    if (Object.prototype.toString.call(this) === '[object Array]')    {        var clone = [];        for (var i=0; i<this.length; i++)            clone[i] = this[i].clone();        return clone;    }     else if (typeof(this)=="object")    {        var clone = {};        for (var prop in this)            if (this.hasOwnProperty(prop))                clone[prop] = this[prop].clone();        return clone;    }    else        return this;}var obj = {a: 25, b: 50, c: 75};var A = obj.clone();var B = obj.clone();A.a = 30;B.a = 40;alert(obj.a + " " + A.a + " " + B.a);var arr = [25, 50, 75];var C = arr.clone();var D = arr.clone();C[0] = 30;D[0] = 40;alert(arr[0] + " " + C[0] + " " + D[0]);
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 365 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號