<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
* 原型模式:
prototype 原型属性
对象的原型拥有的属性,该对象的实例对象也会同时拥有
*/
function Test(){
}
Test.age=20;
var tt=new Test();//这种情况age属性不会再new时候被添加哦
alert(tt.age)//undefine
//--------------------
function Test(){
}
Test.prototype.age=20;//指定原型有的属性
var tt=new Test();
alert(tt.age)//这样就有了值,非undefine了
//-------------------------
function Student(){};
alert(Student.prototype);
for(pro in Student.prototype){
alert(pro);//弹出为空,默认该对象没有任何属性
}
Student.prototype.name="黑马";
Student.prototype.age=3;
Student.prototype.getName=function(){
return this.name;
}
var stu1=new Student();
//stu1.name="传智"//会覆盖原型属性中的值
delete stu1.name;//删除对象实例的属性,原型属性还是存在的哦。
alert(stu1.name);
</script>
</head>
<body>
</body>
</html>
原型设计模式prototype-构造js自定义对象
原创mb60b8936aed2b7 ©著作权
文章标签 JS开发 JS教程 前端开发 文章分类 JavaScript 前端开发
上一篇:观察者设计模式从无到有
-
SpringBoot自定义starter
SpringBoot自定义starter
spring maven ci -
js中数组原型Array、自定义原型函数Array.prototype
全栈y(M
prototype js array 数组 原型 -
设计模式:原型模式(Prototype)设计模式 原型模式 java 深克隆 微信公众号
-
js16--自定义原型对象
Untitled Document
原型对象 html 构造器 配置项 javascript -
设计模式--原型(Prototype)模式
写这些也许有人认为“为了模式而模式”。Insus.NET所想到的,每个大师成为大师之前,也许都得这样做。走路,从小就开始学,直至现在,谁还不是为了走路而走路?一直重复着......很多人没有分享自己的经验,分享自己的过程,分享这东西,它不会因为分享而变少了......感动的故事,是因为分享了历程而让...
Refactoring ADD Abstract KeyValuePair ContainsKey -
mysql 自定义一个字段可以用这个字段当作条件吗
一、系统封装函数MySQL 有很多内置的函数,可以快速解决开发中的一些业务需求,大概包括流程控制函数,数值型函数、字符串型函数、日期时间函数、聚合函数等。以下列出了这些分类中常用的函数。1、控制流程函数case...when根据值判断返回值,类比编程中的IF-ELSE判断。 -- DEMO 01 SELECT CASE DATE_FORMAT(NOW(),'%Y-%m-%d')
db2 replace函数的用法 jpa 自定义sql if mysql 8.0 自定义函数 mysql 连续日期统计