JavaScript library that converts functions to an extended functions. Allows prioritized preprocessor/postprocessor functions to be attached to a function in order to increase its abilities.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
MIT-LICENSE.txt
README.md
xfn.js

README.md

Extended Function Factory

About

  • JavaScript library that converts functions to an extended functions.
  • Allows preprocessor/postprocessor functions to be attached to a function in order to increase its abilities.

Information

Usage

Extending a function

var someFunction = function() { ... };
$xfn(someFunction);

Extending all functions in an object

var someClass = function() { ... };
someClass.prototype = { ... };
$xfn.extend(someClass.prototype);

Adding a preprocessor

someFunction.pre.add(function(result) {
	// Do something.
	arguments[0] = result + '';
	
	// Always return the resulting arguments object to continue normally.
	return arguments;
});

Adding a postprocessor

someFunction.post.add(function(result) {
	// Process the arguments.
	result = result * 10;
	
	// Always return the resulting arguments object to continue normally.
	return arguments;
});