Good day,
I am working with objects, and am confused as to the use of this, and the use of helper functions
Question 1 –
I was hoping someone could explain why the following code works if I set intermediate variables for this.bilex.lexi and this.bilex.tableLex. If I remove them and call this.bilex.lexi and this.bilex.tableLex from whithin the helper function (createListe), the program crashes. Is there an alternate way of doing this? Although the program works, it comes at a cost of readability.
Question 2 – from within the helper function (createListe)
, I am trying to acess the this.findLocation(word), which is a prototype function defined elsewhere. Tracing the code with [url]http://codeboot.org/
What am I not understanding here?
Thanks,
Chris
[CODE]
//constructor is separate part not listed here
Bilexique.prototype.createBilexique = function (){
var index = 0;
[B] var bilexLexi= this.bilex.lexi
var tableLex = this.bilex.tableLex[/B]
var tabToReturn = []
[B]var createListe = function [/B](word, counter, index){
var tabTemp = [];
for (i=0;i<counter;i++){
var desti = [B]this.findLocation(word);[/B]
this.insert(tableLex[index], desti);
index++
};
if (tabTemp.length > this.n) temp.slice(0, this.n);
return tabTemp;
}
for (var i=0;i<tableLex.length;i++){
tabToReturn.push(bilexLexi[i][0]);//mot
tabToReturn[i][1].push(createListe (bilexLexi[i][0], bilexLexi[i][1], index))//table des traductions
}
};