本文共 1567 字,大约阅读时间需要 5 分钟。
define(function () { var now = +new Date(); var util = {}; util.guid = function () { return 'e' + now++; }; util.noop = function () {}; var dontEnumBug = !(({ toString: 1 }).propertyIsEnumerable('toString')); // type 子类 superType 父类 util.inherits = function (type, superType) { var Empty = function () {}; Empty.prototype = superType.prototype; var proto = new Empty(); var originalPrototype = type.prototype; type.prototype = proto; for (var key in originalPrototype) { proto[key] = originalPrototype[key]; } if (dontEnumBug) { // 其实还有好多其它的,但应该不会撞上吧(╯‵□′)╯︵┻━┻ if (originalPrototype.hasOwnProperty('toString')) { proto.toString = originalPrototype.toString; } if (originalPrototype.hasOwnProperty('valueOf')) { proto.valueOf = originalPrototype.valueOf; } } type.prototype.constructor = type; return type; }; util.parseJSON = function (text) { if (!text) { return undefined; } if (window.JSON && typeof JSON.parse === 'function') { return JSON.parse(text); } else { /* jshint evil: true */ return new Function('return (' + text + ');')(); } }; var whitespace = /(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g; util.trim = function (source) { return source.replace(whitespace, ''); }; return util;});
转载地址:http://luell.baihongyu.com/