Class.Reimplement 0.1

A Class.Refactor alternative. Removes the need for an extra wrapper that sets and unsets the 'previous' method which could overshadow an existing property if you aren't careful.



Details

Author
cryptic swarm
Current version
0.1
GitHub
CrypticSwarm/Class.Reimplement
Downloads
2050
Category
Utilities
Tags
Report
GitHub Issues

Releases


Dependencies

  • core/1.2.4: Class

How to use

Pass in an object that is key/function pairs. Reimplement will then run the function in the key/function(initializer) pair passing in the previous function(previousMethod). The initializer function should return a function(newMethod) that uses the previousMethod however it wants.

Syntax

myClass.reimplement({
    someExistingMethod: function(original){
        return function() {
            //do something before
            original();
            //do something after
        }
    }
});

Example

var P = new Class({
        initialize: function() {
                console.log('initializing');
        },
        doStuff: function(){
                console.log('doing stuff!');
        }
});

var a = new P();
a.doStuff();


P.reimplement({

        doStuff: function(func){
                return function(){
                        console.log('before doing stuff');
                        func();
                        console.log('after doing stuff');
                };
        }

});

a.doStuff();

Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus