zoukankan      html  css  js  c++  java
  • JS-09 (Object.create())

    Object.create(): 专门用于在没有构造函数的情况下也能创建子对象

    //var 子对象名=Object.create(父对象)
    //示例

    var father={

      bal:10000000000,

      car:"infiniti"

    }

    var hmm=Object.create(father);

    create()创建出的新对象的__proto__已经被自动的设置为create()的参数,也就是自动继承了父对象

    或者在创建子对象的同时,向子对象中添加自有属性。

    var 子对象=Object.create(父对象,{ //和defineProperties中写的属性格式一样
    属性名: {
    	value: 属性值, 
         writable:true,
    	enumerable:true,
    	configurable:true
    	},
    属性名:{
    	Value: 属性值,
    	... : ...
    	}
    })

    Object.create()可以做三件事:

    1). create()创建一个新对象的意思

    2). create()创建出的新对象的__proto__已经被自动的设置为create()的参数,也就是自动继承了父对象father

    3). 其实create()函数也可以为新创建的子对象添加自有属性

  • 相关阅读:
    colock
    ToggleButton 和 Switch
    radioButon的使用
    kotlin中val和var的区别
    textEdit
    c++ 网络编程基础
    网格布局 GridLayout
    数组、指针和引用
    Hello Word
    Win7-U盘安装出现"We were unable to copy your files. "
  • 原文地址:https://www.cnblogs.com/codexlx/p/12484338.html
Copyright © 2011-2022 走看看