create function in javascript with custom prototype

前端 未结 3 1174
名媛妹妹
名媛妹妹 2021-01-19 01:26

So I created a function like this,

var functionName = function(arg1) { //code logic here; }

At the same time, I need this function to work

3条回答
  •  囚心锁ツ
    2021-01-19 01:47

    You want to implement a delegate to myObj:

         var functionName = function(arg1) { // code }
    
         functionName.myObj = new MyObj();
         for (prop in functionName.myObj) {
           if (functionName.myObj.hasOwnProperty(prop)) {
             functionName.__defineGetter__(prop, function() { return functionName.myObj[prop]; } );
           }
         }
    

提交回复
热议问题