<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
</body> | |
<script type="text/javascript"> | |
function Person(n,g,a){ | |
this.name = n||'张萌萌', | |
this.gender = g||'undefined', | |
this.age = a||18 | |
} | |
Person.prototype.eat = function(){ | |
alert('我喜欢吃黄焖鸡'); | |
} | |
Person.prototype.showName = function(){ | |
alert(this.name); | |
} | |
//属性写在构造函数中,方法写在原型中 | |
var obj = new Person('张可可','boy',40); | |
alert(obj.name); | |
obj.showName(); | |
</script> | |
</html> | |
原型
最新推荐文章于 2017-03-30 15:59:33 发布