prototype.js分析 $w()関数

用例

  • perlのqwみたいなの。
<script>
String.prototype.strip = function(){
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

function $w(string){
	string = string.strip();
	return string ? string.split(/\s+/) : [];
}

console.log(" hoge moge ".strip());
console.log("hoge moge");

console.log($w("foo bar hoge moge "));
</script>