我的javascript之路之对象

来源:互联网 发布:天龙八部网络加速器 编辑:程序博客网 时间:2024/05/01 05:58

// javascript创建对象

1、开辟内存空间  储存新创建的对象 
2、把this设置为当前对象
3、执行函数内部代码
4、返回新创建的对象


function Student(name,score){
//创建对象属性
this.name = name;
this.score = score;
//创建对象方法
this.sayHi = function () {
console.log("我是"+this.name);
}
}

var s1 = new Student("w",99);  //对象的实例化


console.log(s1.name); //对象的调用
s1.sayHi();

0 0
原创粉丝点击