Hi,
I haven't seen Method Overloading when I watch the MicrosoftAjax.js it is possible but I don't have an "official method" to do this. What do you think abut my method ? I think it will be interesting to have this feature in Visual Studio "Orcas".
// Création d'un namespace
Type.registerNamespace('Sample');
// Constructeur de la class Personne
Sample.Person = function(firstName, lastName){
this._firstName = firstName;
this._lastName = lastName;
}
// Rajout des différentes méthodes à notre type
Sample.Person.prototype = {
get_firstName : function(){
return this._firstName;
},
set_firstName : function(value){
this._firstName = value;
},
get_lastName : function(){
return this._lastName;
},
set_lastName : function(value){
this._lastName = value;
},
toString : function(){
if (arguments.length == 1 && Object.getType(arguments[0]) == String){
return this.toString$String.apply(this, arguments);
} else if (arguments.length == 2 && Object.getType(arguments[0]) == String && Object.getType(arguments[1]) == Sample.Person){
return this.toString$String$Person.apply(this, arguments);
} else {
return this.toString$.apply(this, arguments);
}
},
toString$ : function(){
return String.format('je suis {0} {1}', this.get_firstName(), this.get_lastName());
},
toString$String : function(format){
return String.format(format, this.get_firstName(), this.get_lastName());
},
toString$String$Person : function(format, person){
return String.format('{0} , {1}', this.toString(format), person.toString(format));
}
}
// Enregistrement de notre type dans le framework Atlas
Sample.Person.registerClass('Sample.Person');
and we use it like this :
window.pageLoad = function(){
var p = new Sample.Person('Cyril', 'Durand');
alert(p.toString());
alert(p.toString('{0} {1}'));
var p2 = new Sample.Person('Toto', 'Bidule');
alert(p.toString('{0} {1}', p2));
}