This is the same word count function that I showed in the previous post presented in the good old way of adding more properties and methods through the prototype.

String object is extened to have isWhite read only property and getWordCount method.

[cc lang=”actionscript3″]String.prototype.addProperty(‘isWhite’, function () { return !isNaN(this+’ 0′); }, null);

/*Usage Example:-

var str = ” t r”; trace(str.isWhite); //traces true

str+=”.”; trace(str.isWhite); //traces false

*/ String.prototype.getWordCount = function() { if (this.isWhite) { return 0; } var arr = this.split(‘ ‘); var l = arr.length; for (i in arr) { if (arr[i].isWhite) { l–; } } return l; }; /*Usage Example:-

var str = “World is r Not Enough. “; trace(str.getWordCount()); //traces 4 */

[/cc]