-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
87 lines (68 loc) · 2.6 KB
/
utils.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
factory(require, exports, module);
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['require', 'exports', 'module'], factory);
} else {
console && console.error('Unsupported module environment.'); // jshint ignore:line
}
}(this, function (require, exports, module) {
'use strict';
var _ = {
slice: function slice(arr, index, length) {
return Array.prototype.slice.call(arr, index, length || arr.length);
},
isArray: Array.isArray || function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
},
isObject: function isObject(obj) {
return obj === Object(obj);
},
assign: function assign(target, source) {
var key;
for (key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
return target;
},
result: function result(object, property, fallback) {
/*jshint eqnull: true*/
var value = object == null ? undefined : object[property];
/*jshint eqnull: false*/
if (value === undefined) {
value = fallback;
}
return typeof value === 'function' ? value.call(object) : value;
},
bind: (
Function.prototype.bind ?
function bind(func) {
return Function.prototype.bind.apply(func, _.slice(arguments, 1));
} :
function bind(func, context) {
var args = _.slice(arguments, 2);
if (typeof func !== 'function') {
throw new TypeError('Bind must be called on a function');
}
return function () {
func.apply(context, args);
};
}
),
create: Object.create || (function () {
var Creator = function Creator() {
Creator.prototype = proto;
},
proto = Creator.prototype;
return function create(obj) {
Creator.prototype = obj;
return new Creator();
};
}())
};
module.exports = _;
}));