Fluorine icon indicating copy to clipboard operation
Fluorine copied to clipboard

Decorate existing functions to provide debugging tag

Open snowmantw opened this issue 11 years ago • 0 comments

Even after a context function had been defined, we're still able to wrap it in some other scripts like this:

// ... some other necessary code ...
var existing = UI.o.protype.$
IO.o.prototype.get = function()
{
    // should handle and save these calls' arguments
    UI.o.prototype.get.__calls_args.push(arguments)

    // calls is lot enough, but I'm not sure if this condition can be made easily
    if( enough() )    
    {
        handlePreviousArguments()     // may use passed in arguments here
        return existing.apply(this, arguments)    // call the wrapped function
    }
    return UI.o.prototype.$  // return self to accept more calls if not enough
}

This trick is ugly and may be not easy to implement well, but if we handle it well, we can provide users such feature:

IO("/resource/manifest.json")(TAG)
    .get( )(TAG)(BREAK)
    .done()

These functions can come with optional calls to behavior differently.Although I feel it's will be much easier to create new chaining function to "decorate" other functions:

IO("/resource/manifest.json")(TAG)
    .get( ).tag(TAG).break(BREAK)
    .done()

In current stage the later way seems more proper to implement the debug feature.

snowmantw avatar Aug 07 '13 02:08 snowmantw