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.

dynamic_call_params (func, fp) {return func (fp [0], FP [1], FP [2], FP [3], FP [4]], fp [5] ], Fp [6], fp [7], fp [8], fp [9], fp [10], fp [11], fp [12], fp [13], fp [14], fp [15] ], Fp [16], fp [17], fp [18], fp [19]); } Function attachWrapperToFunc {object, funcName, wrapperFunction} {object ["_ _ _ _ _ _ _ _" + FuncName] = object [funcName]; Object [funcName] = function () {return cover function (object, object ["_ original_function _" + funkname], funknam, arguments); }} Function attachWrapperToObject {object (for object, wrapperFunction)} {if (type (object [varna]] == "function") {attachWrapperToFunc (object, vignette, wrapper function); }}}

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

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -