strict_filters/strict_variables when creating engine

This commit is contained in:
harttle
2016-11-07 00:01:02 +08:00
parent 1e7873afc0
commit ddd06e12b5
8 changed files with 203 additions and 90 deletions
+51 -3
View File
@@ -25,27 +25,75 @@ function forOwn(object, iteratee) {
return object;
}
function assign(dst, src) {
dst = dst || {};
/*
* Assigns own enumerable string keyed properties of source objects to the destination object.
* Source objects are applied from left to right.
* Subsequent sources overwrite property assignments of previous sources.
*
* Note: This method mutates object and is loosely based on Object.assign.
*
* @param {Object} object The destination object.
* @param {...Object} sources The source objects.
* @return {Object} Returns object.
*/
function assign(object) {
object = isObject(object) ? object : {};
var srcs = Array.prototype.slice.call(arguments, 1);
srcs.forEach(function(src) {
_assignBinary(object, src);
});
return object;
}
function _assignBinary(dst, src) {
if (!dst) return dst;
forOwn(src, function(v, k) {
dst[k] = v;
});
return dst;
}
function isArray(value) {
return value instanceof Array;
}
function echo(prefix){
function echo(prefix) {
return v => {
console.log('[' + prefix + ']', v);
return v;
};
}
function uniq(arr) {
var u = {},
a = [];
for (var i = 0, l = arr.length; i < l; ++i) {
if (u.hasOwnProperty(arr[i])) {
continue;
}
a.push(arr[i]);
u[arr[i]] = 1;
}
return a;
}
/*
* Checks if value is the language type of Object.
* (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
* @param {any} value The value to check.
* @return {Boolean} Returns true if value is an object, else false.
*/
function isObject(value) {
return value !== null && typeof value === 'object';
}
exports.isString = isString;
exports.isArray = isArray;
exports.isObject = isObject;
exports.forOwn = forOwn;
exports.assign = assign;
exports.uniq = uniq;
exports.echo = echo;