首页 > 代码库 > 经典JS

经典JS

//用apply把document当作this传入getId函数,帮助“修正”this;document.getElementById = (function (func) {    return function () {        return func.apply(document, arguments);    }})(document.getElementById);//调用var getId = document.getElementById;var div = getId(‘div2‘);//函数判断var Type = {};for (var i = 0, type; type = [‘String‘, ‘Array‘, ‘Number‘][i++];) {    (function (type) {        Type[‘is‘ + type] = function (obj) {            return Object.prototype.toString.call(obj) === ‘[object ‘ + type + ‘]‘;        }    })(type);};

 

经典JS