Created
August 14, 2017 12:26
-
-
Save xuanfeng/abcb73d7321f2ae260286ae62ec156d5 to your computer and use it in GitHub Desktop.
util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.type = function (obj) { | |
return Object.prototype.toString.call(obj).replace(/\[object\s|\]/g, '') | |
} | |
_.isArray = function isArray (list) { | |
return _.type(list) === 'Array' | |
} | |
_.slice = function slice (arrayLike, index) { | |
return Array.prototype.slice.call(arrayLike, index) | |
} | |
_.truthy = function truthy (value) { | |
return !!value | |
} | |
_.isString = function isString (list) { | |
return _.type(list) === 'String' | |
} | |
_.each = function each (array, fn) { | |
for (var i = 0, len = array.length; i < len; i++) { | |
fn(array[i], i) | |
} | |
} | |
_.toArray = function toArray (listLike) { | |
if (!listLike) { | |
return [] | |
} | |
var list = [] | |
for (var i = 0, len = listLike.length; i < len; i++) { | |
list.push(listLike[i]) | |
} | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment