Function.regulate >= 0.1.6

Purpose

Create a new function that will only be able to be called the given amount of times

Syntax

Function.regulate ( Functionfnc Numberamount= 1 );

Parameters

fnc
amount
The maximum amount of times the function can be called

Return values

Function

Examples

Create a function that can only be called once

var my_function = Function.regulate(function(a) {
    return a * 10;
});

// The first time, the function will just execute
my_function(1);>>> 10

// The second time, nothing happens and undefined is returned
my_function(2);>>> undefined