Skip to content

Dayjo/joint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

joint.js

Allows the ability to add extra functionality to an existing function by joining an array of functions together.

Example

First include the joint function in your script

function joint(a){var b;return b=a[a.length-1],a.pop(),a=a.length>1?joint(a):a[0],function(){b.apply(new a)}}

or include the js file

<script src="//raw.github.com/Dayjo/joint/master/joint.min.js"></script>

Then use it like this;

// My original function that I want to extend
function my_func() {
  console.log( "Original functionality." );
}

// Function with the new functionality
function new_func() {
  console.log( "New functionality." );
}

// Add the functionality of new_func to my_func 
my_func = joint([ my_func, new_func ]);

// Now run the original function with the new functionality
my_func();

/* CONSOLE OUTPUT:
 > Original functionality.
 > New functionality.
 */

Here it is on jsbin; http://jsbin.com/orIDujE/1/edit?js,console