forked from documentcloud/underscore-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunderscore.function.dispatch.js
35 lines (27 loc) · 1003 Bytes
/
underscore.function.dispatch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Underscore-contrib (underscore.function.dispatch.js 0.3.0)
// (c) 2013 Justin Ridgewell
// Underscore-contrib may be freely distributed under the MIT license.
(function() {
// Baseline setup
// --------------
// Establish the root object, `window` in the browser, or `require` it on the server.
if (typeof exports === 'object') {
_ = module.exports = require('underscore');
}
// Helpers
// -------
// Create quick reference variable for speed.
var slice = Array.prototype.slice;
// Mixing in the attempt function
// ------------------------
_.mixin({
// If object is not undefined or null then invoke the named `method` function
// with `object` as context and arguments; otherwise, return undefined.
attempt: function(object, method) {
if (object == null) return void 0;
var func = object[method];
var args = slice.call(arguments, 2);
return _.isFunction(func) ? func.apply(object, args) : void 0;
}
});
}).call(this);