<!doctype html>
<html>
<head>
<title>标题</title>
<meta charset="utf-8">
<script>
var father={
bal:100000000,
car:"infiniti"
};
Object.create=function(father,props){
console.log("自定义create");
//创建空对象,保存在child中
var child={};
//让child继承father
Object.setPrototypeOf(child,father);
//如果props不是undefined
if(props!==undefined){
//利用defineProperties,向child对象中批量添加props中的属性
Object.defineProperties(child,props);
}
return child;//返回child
}
var child=Object.create(father,{
phone:{value:"iphone7",
writable:true,
enumerable:true,
configurable:true
}
});
console.dir(child);
</script>
</head>
<body>
</body>
</html>
javascript面向对象(十)
最新推荐文章于 2022-08-09 15:00:06 发布