-
Notifications
You must be signed in to change notification settings - Fork 11
Usage
Using sinful is very simple.
You need a single file: sinful.js.
The default philosophy we adopt for augmenting prototypes is "all or nothing", but you can change that in any way you like by supplying an augmentation function that will decide how to deal with conflicts. We call this function bless. Here is the default implementation, already present in the library:
bless = bless || function (thing, name, content) {
if (typeof thing[name] !== 'undefined') {
throw new Error('Sinful: ' + name + ' is already defined.');
}
thing[name] = content;
};
You may decide to treat conflicts in any way you like. This is as easy as defining your own blesser and passing it as an argument to the anonymous function that sinful invokes, at the last line of its code:
void function (bless) {
// all of sinful's code
}( /* Provide your own 'bless' to be used as above if custom behavior needed. */);
And that's that. The only requirement is that the blesser take 3 parameters: thing, name and content.
Here is an example where we maintain the all or nothing approach, changing only the message given if we fail:
void function (bless) {
// all of sinful's code
}(function (thing, name, content) {
if (typeof thing[name] !== 'undefined') {
throw new Error('Error: ' + name + ' is already defined.');
}
thing[name] = content;
});