代码如下:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
}else if (typeof exports === 'object') {
module.exports = factory();
}else {
root.$ = factory();
}
}(this, function () {
'use strict';
var $ = {};
var types = 'Array Object String Date RegExp Function Boolean Number Null Undefined'.split(' ');
function type() {
return Object.prototype.toString.call(this).slice(8, -1);
}
for (var i = types.length; i--;) {
$['is' + types[i]] = (function (self) {
return function (elem) {
return type.call(elem) === self;
};
})(types[i]);
}
return $;
}));
测试如下: