标签:
<script> var person = function(name,city){ this.name = name; this.city =city; } person.prototype.showName = function(){ return this.name; } var p = new person(‘pmx‘,‘shanghai‘); console.log(p.__proto__ == person.prototype); </script>
<script> var person = function(name,city){ this.name = name; this.city =city; } person.prototype.showName = function(){ return this.name; } var p = new person(‘pmx‘,‘shanghai‘); console.log(person.prototype.isPrototypeOf(p)); </script>
<script> var person = function(name,city){ this.name = name; this.city =city; } person.prototype.showName = function(){ return this.name; } var p = new person(‘pmx‘,‘shanghai‘); console.log(Object.getPrototypeOf(p) == person.prototype); </script>
<script> var person = function(name,city){ this.name = name; this.city =city; } person.prototype.age = 26; person.prototype.showName = function(){ return this.name; } var p = new person(‘pmx‘,‘shanghai‘); console.log(p.hasOwnProperty("name")); console.log(p.hasOwnProperty("age")); </script>
<script> var person = function(name,city){ this.name = name; this.city =city; } person.prototype.age = 26; person.prototype.showName = function(){ return this.name; } var p = new person(‘pmx‘,‘shanghai‘); console.log("name" in p); console.log("age" in p); </script>
标签:
原文地址:http://www.cnblogs.com/pmx-pmx/p/5820211.html