<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>构造函数</title>
</head>
<body>
<script>
// 创建一个Obj函数
var Obj = function () {
// 向对象赋值,给他创建一些属性和方法;
this.color = 'black';
this.width = '500px';
this.height = '300px';
this.f = function (box) {
var x = '方泽网络';
return x + box;
}
}
// 原型属性:prototype
Obj.prototype.size = '24px';
Obj.prototype.bg = 'red';
Obj.prototype.gongneng = function () {
return '能打电话';
}
var obj = new Obj()
document.write(obj.size + '<br>');
document.write(obj.bg + '<br>');
document.write(obj.gongneng());
</script>
</body>
</html>
//浏览器输出效果: