Better yet, let us write our own functions.
Quote:
Originally Posted by cbk1994
Adding methods to default objects would indeed be great. In JavaScript, you can edit object "prototypes":
PHP Code:
// from http://www.flzone.com/go?7678
String.prototype.replace = function(pattern, replacement) {
return this.split(pattern).join(replacement);
}
Another idea which I think would work better for GScript would be if you could create a class with the name "TServerPlayer" and all TServerPlayer objects would inherit those methods. This can already be done by joining classes to the player, but for stuff like TServerLevel and TGraalVar (for strings) it would be invaluable. I would love to be able to add string.replace(a, b).
|
PHP Code:
Array.prototype.random = function() {
return this[int(random(0, this.size()))];
}
// Or define it in class 'Array'
public function random() { ... }