`
本来不想注册
  • 浏览: 190870 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Javascript Constructor

阅读更多
//declaring the constructor   
function ArrayMaker(arg1, arg2) {   
    this.someProperty = 'whatever';   
    this.theArray = [ this, arg1, arg2 ];   
}   
// declaring instance methods   
ArrayMaker.prototype = {   
    someMethod: function () {   
        alert( 'someMethod called');   
    },   
    getArray: function () {   
        return this.theArray;   
    }   
};   
  
var am = new ArrayMaker( 'one', 'two' );   
var other = new ArrayMaker( 'first', 'second' );   
  
am.getArray();   
// => [ am, 'one' , 'two' ]  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics