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

js中Object.create實(shí)例用法詳解

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

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

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

實(shí)例

// father 對(duì)象
let father = {
    name: 'father',
    friend: ['abby', 'bob']
}
 
// 生成新實(shí)例對(duì)象 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' ]
 
// 生成新實(shí)例對(duì)象 child2
let child2 = Object.create(father)
console.log(child2.name) //father
console.log(child2.friend) //[ 'abby', 'bob', 'chely' ]

知識(shí)點(diǎn)擴(kuò)展:

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

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"

運(yùn)行結(jié)果

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

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

相關(guān)文章

最新評(píng)論

手游| 华容县| 建德市| 科尔| 剑川县| 甘德县| 六枝特区| 桐乡市| 睢宁县| 金平| 乐安县| 阜城县| 鲁山县| 登封市| 山西省| 通化县| 鱼台县| 镶黄旗| 延长县| 前郭尔| 开原市| 林西县| 太和县| 海门市| 温泉县| 嘉定区| 巴南区| 抚松县| 金平| 斗六市| 都匀市| 聂荣县| 钟山县| 福州市| 宿松县| 东乌珠穆沁旗| 开封县| 凤翔县| 赣榆县| 阜宁县| 黔东|