Pourquoi ne peut on pas acc
Bonjour,
Je commence à apprendre JS.
Code:
1 2 3 4 5 6 7 8 9 10
| var f1 = function () {
this.v1 = 5;
}
f1.prototype.get_v1 = function () { return this.v1; };
var f2 = new f1();
f1.v1 // return nothing
f1.get_v1() // nothing
f2.v1 // return 5
f2.get_v1() // return 5 |
Pourquoi f1.v1 and f1.get_v1 retourne rien du tout ?
Est-ce que l'explication est que le this de f1 est l'objet de sa propriété prototype et n'est utilisé que pour être un constructeur ?
Merci pour vos explications.
Sam