functionGuard forge

Allows you to add and remove control functions to class methods that determine if the function should run or not.



Details

Author
Phil Carty
Current version
forge
GitHub
codelish/functionGuard
Downloads
1280
Category
Native
Tags
Report
GitHub Issues

Releases


Dependencies

  • _self_/_current_: core/1.3: [Class]

How to use

For new classes:

var someClass = new Class({
    Implements: [Guard]
});

For existing classes:

someClass.implement(Guard);

Adding a guard:

this.addGuard("someFunction", function(foo, bar){
    // do something, returning true to call the guarded function or false to cancel
});

Removing a guard:

this.removeGuard("someFunction");

By returning TRUE the function being guarded will be called, returning FALSE will result in it not being called.

You do not need to specify the parameters in the guard function unless you wish to validate against them.


Reference

addGuard(functionName, guardFunction);

this.addGuard("someFunction", function(foo, bar){
    // do something
});

addGuards(object);

this.addGuards({
    "someFunction": function(foo, bar){ 
        // do something
    },
    "anotherFunction": function(value){
        // do something
    }
});

removeGuard(functionName);

this.removeGuard("someFunction");

removeGuards(array);

this.removeGuard(["someFunction","anotherFunction"]);

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