How do you create a method for a custom object in JavaScript?

前端 未结 7 1250
野的像风
野的像风 2020-11-28 22:21

Is it like...

var obj = new Object();

obj.function1 = function(){
    //code
}

or something like that?

7条回答
  •  甜味超标
    2020-11-28 23:13

    
    Function.prototype.implement = function(member, value) {
       this[member] = value;
       return this;
    }
    
    function MyFunction() {
     //...
    }
    
    (function($){
    
     $.implement("a", "blabla")
     .implement("b", function(){ /* some function */ })
     .implement("c" {a:'', b:''});
    
    })(MyFunction);
    

提交回复
热议问题