返回到:JavaScript对象:JavaScript String 对象
定义和用法
prototype 属性允许您向对象添加属性和方法
注意: Prototype 是全局属性,适用于所有的 Javascript 对象。
语法
object.prototype.name=value所有主要浏览器都支持 prototype 属性
实例
适用 prototype 属性给对象添加属性:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(Web176.com)</title>
</head>
<body>
<script>
function employee(name,jobtitle,born){
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
}
var fred=new employee("Fred Flintstone","Caveman",1990);
employee.prototype.salary=null;
fred.salary=20000;
document.write(fred.salary);
</script>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/jsarrtips/2973.html
支付宝
微信