jQuery源码 — trim方法
trim方法定义在jQuery.prototype
var trim = String.prototype.trim,//在jQuery闭包最开始的地方定义的trimLeft = /^[\s\xA0]+/;trimRight = /[\s\xA0]+$/;············// Use native String.trim function wherever possibletrim: trim ?function( text ) {return text == null ?"" :trim.call( text );} :// Otherwise use our own trimming functionalityfunction( text ) {return text == null ?"" :text.toString().replace( trimLeft, "" ).replace( trimRight, "" );}// IE doesn't match non-breaking spaces with \strimLeft = /^[\s\xA0]+/;trimRight = /[\s\xA0]+$/;
var trim = String.prototype.trim ? function( text ) {if( !text ) {return '';} else {return String.prototype.trim.call(text);}} : function( text ) {var trimLeft = /^[\s\xA0]+/,trimRight = /[\s\xA0]+$/;return function(text){if( !text ) {return '';}else{return text.toString().replace(trimLeft, '').replace(trimRight, '');}}}()trim(' abc ');