没啥用的 JavaScript 字符串模板

没啥用的 JavaScript 字符串模板

最近在做些关于模板引擎的事情,花半小时搞了个简陋版的字符串模板。 追求简便,直接添加到 String.prototype 上了。 How it work String.prototype.format = (function() { // debug_level: [0, 1, 2] => ['igorne', 'warning', 'error'] var default_option = { l_token: '{{', r_token: '}}', debug_level: 1 } var vail = function (raw, key, debug_level) { if (raw === null) {return '';} if (raw === undefined) { switch (debug_level) { case 2: throw new Error('the

重新敲一遍代码,胜过拷贝粘贴

重新敲一遍代码,胜过拷贝粘贴

原文地址 (original source): http://xion.io/post/programming/dont-copy-paste-retype.html 作者 (author): https://twitter.com/Xion__ 译文: http://www.labazhou.net/2015/10/dont-copy-paste-retype/ 译者: 腊八粥: http://www.labazhou.net/ 如今这个时代,Google 和 Stack Overflow 已经成为了很多开发者不可或缺的工具。但是最近,后者貌似名声坏了。一方面,是因为表面上特别、有时候会偏离适度的原则。说得更中