function Block(func, tag) { var _r_function = /^function\b\s*([\$\S]*)\s*\(/; var _r_codebody = /[^{]*\{([\d\D]*)\}$/; var _r_params = /[^\(]*\(([^\)]*)\)[\d\D]*/; tag = (tag || 'body').toLowerCase(); with (func.toString()) {
在我《惰性函數》一文引起一些爭議,有人總是把惰性函數與緩衝函數(Memoization)混為一談。雖然都是緩衝了結果,但最大的區別是一個改寫函數本身,一個沒有。那我就說一下緩衝函數吧。簡而言之,就是把上次運算的結果放到一個數組或對象中。拿什麼做實驗好呢?就拿那個Fibonacci數列吧,估計IE6會比較嗆,一般5秒運算不了就假死了。我們先看消耗時間,再看結果。一直接用遞迴實現: function fib(n){ if (n == 0 || n == 1)
綜合眾人的意見,此版本做了許多改進,如對注釋抽取的最佳化,增加對script標籤的支援,即時性的測試等等。// dom.abut v2 (annotations-based unit testing by 司徒正美)// http://www.cnblogs.com/rubylouvre/archive/2010/11/08/1868638.html(function(){ //ecma262新擴充 if(!Object.keys){ var _dontEnum =
為公司起草的javascript編程規範,參考了網上的許多資料,尤其是google的規範。現在放出來,希望能拋磚引玉,大家多提寶貴意見。本規範是針對javascript函數式編程風格與公司嚴重依賴於jQuery進行編碼的現實制定出來。禁止使用eval,with與caller(ecma262 v5 的use strict要求)。eval只允許在加密時機器產生。聲明變數必須加上 var
In an earlier article, I mentioned that Boing-Boing had a few issues when they wanted to use @font-face embedding inside their website. In short, the problem was that some fonts look bad on computer monitors without font-smoothing enabled in the
Written by Magnus Holm.From Wikipedia’s article on JSONJSON was based on a subset of the JavaScript scripting language.All JSON-formatted text is also syntactically legal JavaScript code.JSON is a subset of JavaScript.All these years we’ve heard it
群裡abcd提出問題,現在有以下三個實現,歡迎大家參與(注意,為了相容IE6,不能使用str[i],要用str.charAt(i);不能使用slice,replace等原生函數):GrayZhang的實現String.prototype.substring = function(start, length) { var array = []; for (var i = start; i 我的實現://by 司徒正美 2011.8.18String.prototype.indexOf
var C = function(){ this._methodList = [];}C.prototype.fire = function(obj){ var instance = this; while(obj = this._methodList.shift()){ if(isFinite(obj.fn)){ var time = new Date; instance.timeoutID = setTimeout(