码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript构建对象重点(一)

时间:2015-01-22 01:37:16      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

        
    //person类
    var Person = { making:function (name,age) { this.name = name; this.age = age; }, say:function () { document.write(this.name+" "+this.age+" "); } }     //创建对象的函数,需要传递两个参数,一个是类(Person),一个是类的实参。 function Create(obj,arg){        function Create_inter(){ obj.making.apply(this,arg); //Create_inter相当于集成了Person } Create_inter.prototype = obj;//把Person付给Create_inter的原型 return new Create_inter();//返回用Create_inter创造的拥有Person属性和方法的对象。 }      var stu1 = new Create(Person,["stu1",20]);//stu1 20 var stu2 = new Create(Person,["stu2",21]);//stu2 21 var stu3 = new Create(Person,["stu3",22]);//stu3 22 stu1.say(); stu2.say(); stu3.say();

   需要继续思考的是:stu1,stu2,stu3中say()函数是公用一个,还是各自一个?记得代码验证下。
    

 

Javascript构建对象重点(一)

标签:

原文地址:http://www.cnblogs.com/stevenotes/p/4240512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!