Sunday, August 05, 2007

prototype javascript library String and Object extend example


<script type="text/javascript" charset="utf-8">
function doc (argument) {
document.write(argument);
document.write("<br />\n");
}

Object.extend(String, {
win: doc('this is object of Window ? ' + (this instanceof Window)), // true
size: function (str) {
return arguments.callee.print(str);
}
});

String.size.print = function (arg) {
//doc('String.size.print() = ' + arg.length);
return arg.length;
};

var s = "string size";

doc('String.size = ' + String.size(s));
doc(String.size.print(s));

var wStr = $w('a b c d e f g');
doc(wStr.inspect());
</script>

No comments :