// Attempt to make generics safe in the face of downstream// modifications.// There is no situation where this is necessary.// If you need a security guarantee, these primordials need to be// deeply frozen anyway, and if you don’t need a security guarantee,// this is just plain paranoid.// However, this does have the nice side-effect of reducing the size// of the code by reducing x.call() to merely x(), eliminating many// hard-to-minify characters.// See Mark Miller’s explanation of what this does.// http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programmingvaruncurryThis;// I have kept both variations because the first is theoretically// faster, if bind is available.if(Function.prototype.bind){varFunction_bind=Function.prototype.bind;uncurryThis=Function_bind.bind(Function_bind.call);}else{uncurryThis=function(f){returnfunction(){returnf.call.apply(f,arguments);};};}vararray_slice=uncurryThis(Array.prototype.slice);
array_slice=uncurryThis(Array.prototype.slice)=Function.prototype.bind.bind(Function.prototype.bind.call)(Array.prototype.slice)=Function.prototype.bind.call.bind(Array.prototype.slice)//Function.prototype.bind.call.bind is safe=Array.prototype.slice.call//Array.prototype.slice.call is safe//Array.prototype.slice is also safe
不过,Q的注释里写的很清楚,uncurry在这里不是必要的… 写写而已…
一些参考:
这篇文章 详细介绍了safe meta programming,对uncurry做了定义和代码演示。