Javascript is very cool in the way that i handles objects. The way that it lets you dynamically extend objects with properties and methodes, I find very cool.
Yes you need to keep focus due to this "anercistic" structure of javascript - sometimes you hate it but most of the times you probertly love it :-)
Anyway, I found a good example of this object extending feature. A trim method is not included in the standard javascript String object. So here you are - a way to extend String with a Regular Expression based trim() method:
String.prototype.trim = function() {
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
(I found it here: Codeproject)
/Sten
Showing posts with label utility. Show all posts
Showing posts with label utility. Show all posts
Sunday, October 21, 2007
Javascript - trim() method...
By
Sten Hougaard
on
Sunday, October 21, 2007
0
kommentarer
Etiketter: Javascript, RegExp, utility
Wednesday, October 3, 2007
A simple effective HTML-escape/encode function in Javascript!
At LUNARMEDIA I found this function below will take a string and return a HTML-encoded version of it!
function escapeHTML (str)
{
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
};
By
Sten Hougaard
on
Wednesday, October 03, 2007
0
kommentarer
Etiketter: Javascript, utility
Subscribe to:
Posts (Atom)