Supportnet / Forum / Skripte(PHP,ASP,Perl...)
von benutzer defenierte methode
Frage
hey! eine function wo ich selbst gemacht habe soll eine methode sein. zun beispiel var str="string"; var crypt=str.rot13; alert(crypt); wie geht das?
Antwort 1 von kicia
Ich würde es so machen:
var str = new c_str();
str.setvalue("456");
str.setabc("789");
alert(str.getvalue() + "\r\n" + str.getabc());
//------------
function c_str()
{
this.value = "xyz";
this.abc = "123";
this.getvalue = function () { return this.value; }
this.setvalue = function (s) { this.value = s; }
this.getabc = function () { return this.abc; }
this.setabc = function (s) { this.abc = s; }
//...
}
Antwort 2 von js_rulez
cool! abba nicht so wie ich will. abba cool! kicia rulez!
gibt noch andre möglichkeit dabei?
gibt noch andre möglichkeit dabei?
Antwort 3 von kicia
Ich glaube, ich verstehe nicht ganz, was gefragt ist.
Willst Du eine Methode zum String-Objekt hinzufügen?
Beispiel:
Willst Du eine Methode zum String-Objekt hinzufügen?
Beispiel:
String.prototype.xyz = c_xyz;
var str = new String("123");
function c_xyz()
{
return "<h1>" + this.valueOf() + "</h1>";
}
alert(str.xyz());
Antwort 4 von js_rulez
coole schaisse! du bist der master von supportnet!!!!!!! thx

