javascript - Arguments of function inside a function -
i want create objects don't know how write arguments of function inside function. here code comments explain better.
function troop(rss, time, offense, defense){ this.rss= rss; this.time= time; this.offense= offense; this.defense= function types(a, b, c, d){ this.a= a; this.b= b; this.c= c; this.d= d; } } dwarf = new troop(1,2,3, new types(11,22,33,44)); // wrong alert(dwarf.defense.a) // how can access values after?
thanks.
you want types
own function, can pass in object troop
constructor.
function types(a, b, c, d) { this.a= a; this.b= b; this.c= c; this.d= d; } function troop(rss, time, offense, defense){ this.rss= rss; this.time= time; this.offense= offense; this.defense= defense; } dwarf = new troop(1,2,3, new types(11,22,33,44)); // these lines right alert(dwarf.defense.a) // it's function definition wrong :)
in general capitalize class names types
, , keep variables dwarf
lower-case, that's more question of style, not functionality.
Comments
Post a Comment