Skip to content

Commit 058e5e2

Browse files
committed
Consider using function to check type of variable
I think we should we function to check type of variable like underscore or lodash to make it more flexible or easier to test
1 parent e77af77 commit 058e5e2

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

CCBoot.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,63 @@ cc.extend = function(target) {
103103
return target;
104104
};
105105

106+
/**
107+
* Check the obj whether is function or not
108+
* @param {*} obj
109+
* @returns {boolean}
110+
*/
111+
cc.isFunction = function(obj) {
112+
return typeof obj == 'function';
113+
};
114+
115+
/**
116+
* Check the obj whether is number or not
117+
* @param {*} obj
118+
* @returns {boolean}
119+
*/
120+
cc.isNumber = function(obj) {
121+
return typeof obj == 'number' || Object.prototype.toString.call(obj) == '[object Number]';
122+
};
123+
124+
/**
125+
* Check the obj whether is string or not
126+
* @param {*} obj
127+
* @returns {boolean}
128+
*/
129+
cc.isString = function(obj) {
130+
return typeof obj == 'string' || Object.prototype.toString.call(obj) == '[object String]';
131+
};
132+
133+
/**
134+
* Check the obj whether is array or not
135+
* @param {*} obj
136+
* @returns {boolean}
137+
*/
138+
cc.isArray = function(obj) {
139+
return Object.prototype.toString.call(obj) == '[object Array]';
140+
};
141+
142+
/**
143+
* Check the obj whether is undefined or not
144+
* @param {*} obj
145+
* @returns {boolean}
146+
*/
147+
148+
cc.isUndefined = function(obj) {
149+
return typeof obj == 'undefined';
150+
};
151+
152+
/**
153+
* Check the obj whether is object or not
154+
* @param {*} obj
155+
* @returns {boolean}
156+
*/
157+
cc.isObject = function(obj) {
158+
var type = typeof obj;
159+
160+
return type == 'function' || (obj && type == 'object');
161+
}
162+
106163
/**
107164
* Check the url whether cross origin
108165
* @param {String} url

0 commit comments

Comments
 (0)