//Eloquent JS object snippet 6

//Eloquent JS object snippet 6 function Rabbit(type) { this.type = type; } var killerRabbit = new Rabbit("killer"); var blackRabbit = new Rabbit("black"); console.log(blackRabbit.type); /*les constructeurs, en fin de compte, toutes les fonctions (utilisees pour creer des objets) fabriquent une propriete nommee prototype (j'aurais dit un objet prototypal), derive du fondamental "Object.prototype", qui sert de prototype a tous les objects crees a partir du constructeur. Ici appelons le 'Rabbit.prototype' On va l'appeler ici en ecrivant "blackRabbit.speak*/ Rabbit.prototype.speak = function(line) { console.log("The " + this.type + " rabbit says '" + line + "'"); }; blackRabbit.speak("Doom..."); console.log(Rabbit.prototype); console.log(Object.prototype); console.log(Rabbit); console.log(killerRabbit);

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.