js构造方法

  • Post author:
  • Post category:其他
//定义构造方法

 function stu1()

{

this.stuNo=”20160001″

this.stuName=”刘豪”;

this.method= function()

{

eturn “刘豪长的贼帅”;

}

}

var student=new stu1();

alert(student.method());

用var声明的 变量和方法 都是对象People的私有变量和私有方法,不能在外部调用

function People(){

var name=””;

var work=function()

{

alert(“调用的是构造方法里面的 work() 方法”);

}

}

//向构造对象里添加变量和方法,用prototype

People.prototype.gender=”男”;

People.prototype.eat = function()

{

alert(“刘豪需要吃饭才能生存”);

}

引用数据类型 传递 地址

String类型数据 的各种方法

Date  

方法重写

var now = new Date();

Date.prototype.getVarDate(){

return this.getFullYear()+this.getMonth()+this.getDate();

Array

数组排序 Array.sort();

array.join(“,”)  每个数组元素后都加上“,”形成字符串

array.splice(Index,delNum,”insertElement”)  从index元素开始删除delNum个元素,然后插入 insertElement  


版权声明:本文为csdn13461916098原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。