javascript function modification -
I am trying to write a logger object that logs messages to the screen. Here is my code, which is to be logged in each function, I am writing logger start and loggerend function at the beginning and end of my operation. But I run the Thomas Code Automatic for each function. Function is a way of modifying the prototype, so each function call can run automatically. (I am not using any javascript framework.)
edit: it Rewrite the function to make it more modular
Well, this is a scary way to do this, but sometimes I need to override some tasks like this. It works well, allows any type of adaptation and easy to understand (still horror) .
However, you will need to store all your tasks in any type of global item. See examples for details.
and some use examples:
var myProgram = new object (); MyProgram.function_one = function (a, b, c, d) {warning (a + b + c + d); } MyProgram.function_two = function (a, b) {warning (a * b); } MyProgram.function_three = function (a) {Warning (A); } Function loggerfirefunction (function object, orffunction, orffunction name, orantamem) {warning ("start:" + origFunctionName); Var result = dynamic_loc_params (origFunction, origParams); Warning ("end" + origFunctionName); Return result; } AttachWrapperToObject (myProgram, logarobe function); MyProgram.function_one (1,2,3,4); MyProgram.function_two (2,3); MyProgram.function_three (5);
The output will be: start, 10, end, start, 6, end, start, 5, end
Allows you to auto-wrap each function with a custom written wrapper function.
Comments
Post a Comment