~yacinechaouche/+junk/BZR

« back to all changes in this revision

Viewing changes to CODE/TEST/JAVASCRIPT/questions.txt

  • Committer: yacinechaouche at yahoo
  • Date: 2015-01-14 22:23:03 UTC
  • Revision ID: yacinechaouche@yahoo.com-20150114222303-6gbtqqxii717vyka
Ajout de CODE et PROD. Il faudra ensuite ajouter ce qu'il y avait dan TMP

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
1) Comment créer un objet en passant des paramètres à un constructeur en utilisant Object.create() ?
 
2
 
 
3
ex.
 
4
 
 
5
horry = {
 
6
    name : "horry",
 
7
    meow : function(){console.debug(this.name + ": meow !")}
 
8
};
 
9
 
 
10
horry.meow();
 
11
 
 
12
Create an object mike that inherits from horry and set its name to mike in one single call to Object.create.
 
13
 
 
14
2) What's wrong in the followwing code ?
 
15
 
 
16
person = function(){
 
17
  person.prototype.foo = function (){console.debug("hehehe")}
 
18
}
 
19
person();
 
20
p = new person();
 
21
 
 
22
me = Object.create(person);
 
23
me.foo(); // why can't me find foo even when it's defined in its prototype person.
 
24
 
 
25
3) What's wrong with this code ? 
 
26
 
 
27
howard = {
 
28
  name : "howard";
 
29
  init : function(name){this.name = name; return this;}
 
30
};
 
31
 
 
32
jack = Object.create(howard).init("jack")
 
33
console.debug(jack.name);
 
34
 
 
35
 
 
36
 
 
37
 
 
38
 
 
39