js中的原型对象
<!DOCTYPE html
>
<html
>
<head
>
<meta charset
="UTF-8">
<title
>js中的原型对象
</title
>
<script type
="text/javascript">
function Person(name
, age
, gender
){
this.name
= name
;
this.age
= age
;
this.gender
= gender
;
this.sayName = function(){
console
.log(this.name
);
};
}
Person
.prototype
.caicai = function(){
console
.log("oasdaofad")
}
Person
.prototype
.xiao
= "haha";
var p1
= new Person("hahaha",22);
p1
.sayName();
p1
.caicai();
console
.log(p1
.__proto__
== Person
.prototype
)
console
.log(typeof p1
.__proto__
.__proto__
.__proto__
)
console
.log(name
in p1
)
console
.log("name" in p1
)
console
.log(p1
.hasOwnProperty("name"))
console
.log(p1
.hasOwnProperty("xiao"))
</script
>
</head
>
<body
>
</body
>
</html
>
转载请注明原文地址: https://lol.8miu.com/read-16327.html