Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare functions dynamically. #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 15 additions & 33 deletions dist/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,23 @@

'use strict';

var getType = function (item) {
var methods = {},
types = ['Array', 'Object', 'String', 'Date', 'RegExp', 'Function', 'Boolean', 'Number', 'Null', 'Undefined'],
getType = function (item) {
return Object.prototype.toString.call(item);
},
checkType = function(item){
return getType(item) === '[object '+this+']';
},
bind = function (fn, context) {
return function () {
return fn.apply(context, arguments);
};
};

return {
isArray: function (elem) {
return getType(elem) === '[object Array]';
},
isObject: function (elem) {
return getType(elem) === '[object Object]';
},
isString: function (elem) {
return getType(elem) === '[object String]';
},
isDate: function (elem) {
return getType(elem) === '[object Date]';
},
isRegExp: function (elem) {
return getType(elem) === '[object RegExp]';
},
isFunction: function (elem) {
return getType(elem) === '[object Function]';
},
isBoolean: function (elem) {
return getType(elem) === '[object Boolean]';
},
isNumber: function (elem) {
return getType(elem) === '[object Number]';
},
isNull: function (elem) {
return getType(elem) === '[object Null]';
},
isUndefined: function (elem) {
return getType(elem) === '[object Undefined]';
}
};
for( var i = 0, len = types.length; i < len; i++){
methods['is'+types[i]] = bind(checkType, types[i]);
}

return methods;
});
2 changes: 1 addition & 1 deletion dist/axis.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 15 additions & 33 deletions src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,23 @@

'use strict';

var getType = function (item) {
var methods = {},
types = ['Array', 'Object', 'String', 'Date', 'RegExp', 'Function', 'Boolean', 'Number', 'Null', 'Undefined'],
getType = function (item) {
return Object.prototype.toString.call(item);
},
checkType = function(item){
return getType(item) === '[object '+this+']';
},
bind = function (fn, context) {
return function () {
return fn.apply(context, arguments);
};
};

return {
isArray: function (elem) {
return getType(elem) === '[object Array]';
},
isObject: function (elem) {
return getType(elem) === '[object Object]';
},
isString: function (elem) {
return getType(elem) === '[object String]';
},
isDate: function (elem) {
return getType(elem) === '[object Date]';
},
isRegExp: function (elem) {
return getType(elem) === '[object RegExp]';
},
isFunction: function (elem) {
return getType(elem) === '[object Function]';
},
isBoolean: function (elem) {
return getType(elem) === '[object Boolean]';
},
isNumber: function (elem) {
return getType(elem) === '[object Number]';
},
isNull: function (elem) {
return getType(elem) === '[object Null]';
},
isUndefined: function (elem) {
return getType(elem) === '[object Undefined]';
}
};
for( var i = 0, len = types.length; i < len; i++){
methods['is'+types[i]] = bind(checkType, types[i]);
}

return methods;
});