(D.克罗克福德)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(D.克罗克福德)相关的知识,希望对你有一定的参考价值。
Remedial javascript As Proposed by Douglas Crockford (http://javascript.crockford.com/remedial.html)
/* Author: Douglas Crockford Source: http://javascript.crockford.com Description: Remedial Javascript As Proposed by Douglas Crockford (http://javascript.crockford.com/remedial.html) */ var Remedial = (function(){ String.prototype.entityify = function () { return this.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); }; String.prototype.quote = function () { var c, i, l = this.length, o = '"'; for (i = 0; i < l; i += 1) { c = this.charAt(i); if (c >= ' ') { if (c === '\' || c === '"') { o += '\'; } o += c; } else { switch (c) { case '': o += '\b'; break; case 'f': o += '\f'; break; case ' ': o += '\n'; break; case ' ': o += '\r'; break; case ' ': o += '\t'; break; default: c = c.charCodeAt(); o += '\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); } } } return o + '"'; }; String.prototype.supplant = function (o) { return this.replace(/{([^{}]*)}/g, function (a, b) { var r = o[b]; return typeof r === 'string' || typeof r === 'number' ? r : a; } ); }; String.prototype.trim = function () { return this.replace(/^s+|s+$/g, ""); }; // Do whatever you want here var R = { typeOf: function(value) { var s = typeof value; if (s === 'object') { if (value) { if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length')) && typeof value.splice === 'function') { s = 'array'; } } else { s = 'null'; } } return s; }, isEmpty: (o) { var i, v; if (typeOf(o) === 'object') { for (i in o) { v = o[i]; if (v !== undefined && typeOf(v) !== 'function') { return false; } } } return true; } } return R; })();
以上是关于(D.克罗克福德)的主要内容,如果未能解决你的问题,请参考以下文章
他十年前的书在前端圈人手一本,豆瓣评分9.1。现在,王者归来了!