Merge two functions?

后端 未结 5 1177
礼貌的吻别
礼貌的吻别 2021-01-24 04:32

Say, I have two functions:

function foo() {
  this.lorem = \'ipsum\';
}

function boo() {
  console.log(this.lorem);
}

And I want to insert the

5条回答
  •  无人及你
    2021-01-24 04:42

    If you don't want to modify the existing functions do this:

    function foo() {
      this.lorem = 'ipsum';
    }
    
    function boo() {
      console.log(this.lorem);
    }
    
    
    function bar() {
        boo.call(new foo);
    }
    
    bar();
    

    Here's a JSFiddle of it in action: http://jsfiddle.net/8Wb6T/

提交回复
热议问题