面向对象程序设计

构造函数都是以大写字母开头,以大写字母开头的不一定是构造函数。

Math对象

比较

1)Math.min():
返回一组数中的最小值
2)Math.max():
返回一组数中的最大值

取整

1)Math.ceil():向上取整

2)Math.floor():向下取整

3)Math.round():四舍五入

随机数

1)Math.random():返回0-1之间的随机数,不包含1

Date 日期对象 构造函数对象

new date=new Date();

参数 0:当前日期

1:设置时间 new Date(2020,9,1); 想要设置2020.10.1

new Date("2020/10/1"); 使用字符串设置月份时,不需要特别修改月份

new Date("2020-10-1");

new Date(毫秒数);

倒计时设计

面向对象

工厂模式

优点:简化代码的操作(封装)

缺点:对象不能细分,共有属性和方法浪费内存

构造函数模式

function Student(name,age,gender){

this.name=name;

this.age=age;

this.gender=gender;

}

var stu1=new Student("lisi",20,"men");

原型对象模式

function Student(name,age,gender){

this.name=name;

this.age=age;

this.gender=gender;}

Student.prortotype.say=function(){}

var stu1=new Student();

var stu2=new Student();

stu1.say();

stu1.say==stu2.say;

继承

让子类的原型指向父类的实例

function Rich(name,age,gender){
this.name=name;
this.age=age;
this.gender=gender;
}
Rich.prototype.money=["card1","card2","card3"];
Rich.prototype.enjoy=function(){
  alert("enjoy");
}
function Poor(name,age,gender,color){
this.name=name;
this.age=age;
this.gender=gender;
this.color=color;
}
Poor.prototype=Rich.prototype;
//Rich.prototype.constructor=Poor;
Poor.prototype.work=function(){
  alert("work--");
}
var p1=new Poor("tom",20,"men","black");
console.log(p1.money);
console.log(p1.constructor);

执行结果:

[ 'card1', 'card2', 'card3' ]
[Function: Rich]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值