Inject javascript into a javascript function

前端 未结 7 1786
别跟我提以往
别跟我提以往 2021-02-04 13:25

I\'ve got a weird question in that I need to inject some javascript into another javascript function. I am using a framework which is locked so I can not change the existing fun

相关标签:
7条回答
  • 2021-02-04 14:06

    I'm not sure what you mean by "locked" - JavaScript is interpreted by your browser. Even if it has been minified or encoded, you can still copy the source of that function from source of the page of script. At that point, you reassign the original function to one of your own design, which contains the copied code plus your own.

    var id;
    var myFunction = function() {
      // code copied from their source, which contains the variable needed
    
      // insert  your own code, such as for copying the needed value
      id = theirIDvalue;
    
      // return the value as originally designed by the function
      return theirValue;
    };
    
    theirObject.theirFunction = myFunction;
    
    0 讨论(0)
提交回复
热议问题