最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js中Object.create實例用法詳解

 更新時間:2021年10月05日 08:32:49   作者:小妮淺淺  
在本篇文章里小編給大家整理的是一篇關于js中Object.create實例用法及相關基礎內(nèi)容,有興趣的朋友們可以學習下。

1、用Object.create()方法創(chuàng)建新對象,并使用現(xiàn)有對象提供新對象的proto。

2、提供兩個參數(shù),第一個是新創(chuàng)建的原型對象,第二個是為新創(chuàng)建的對象添加屬性的對象。

實例

// father 對象
let father = {
    name: 'father',
    friend: ['abby', 'bob']
}
 
// 生成新實例對象 child1
let child1 = Object.create(father)
 
// 更改值類型屬性
child1.name = '修改了name'
console.log(child1.name) //修改了name
 
// 更改引用類型值
child1.friend.push('chely')
console.log(child1.friend) //[ 'abby', 'bob', 'chely' ]
 
// 生成新實例對象 child2
let child2 = Object.create(father)
console.log(child2.name) //father
console.log(child2.friend) //[ 'abby', 'bob', 'chely' ]

知識點擴展:

Object.create()創(chuàng)建方法實例

const person = {
  isHuman: false,
  printIntroduction: function() {
    console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
  }
};

const me = Object.create(person);

me.name = 'Matthew'; // "name" is a property set on "me", but not on "person"
me.isHuman = true; // inherited properties can be overwritten

me.printIntroduction();
// expected output: "My name is Matthew. Am I human? true"

運行結果

> "My name is Matthew. Am I human? true"

到此這篇關于js中Object.create實例用法詳解的文章就介紹到這了,更多相關js中Object.create方法是什么內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

农安县| 佳木斯市| 崇阳县| 五大连池市| 温泉县| 涪陵区| 温州市| 海兴县| 清镇市| 慈溪市| 华亭县| 石嘴山市| 淳安县| 雅安市| 宝山区| 盱眙县| 白沙| 汉阴县| 赤水市| 凤庆县| 宣武区| 南通市| 和田县| 游戏| 兴海县| 潜江市| 上犹县| 贵溪市| 望奎县| 垫江县| 宜章县| 山东省| 武义县| 德钦县| 常宁市| 抚远县| 平乐县| 宜城市| 梅河口市| 玛纳斯县| 隆德县|