search

Home  >  Q&A  >  body text

javascript - How to add content to function in another file

Test.html calls two js files a.js and b.js:

There is a

in the a.js file
function test(){
    console.log(1);
}

Now I want to add a

to the test function in b.js
console.log(2);

The goal is to output 1 and 2 no matter where test() is called, how to write it

phpcn_u1582phpcn_u15822838 days ago374

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 10:51:31

    var rawTest = test;
    test=function(){
        rawTest();
        console.log(2);
    }

    //
    test();

    reply
    0
  • Cancelreply