Having some trouble getting 'this' to behave as I would expect it -
Basically, I have an object, and I am unable to access an array in the object from a function within the same object -
It looks like this:
var articles = {
article : {
1: {
title : 'This is a Title',
content : 'This is the content of the article'
},
2: {
title : 'This is the second article',
content : 'This is the second article content'
},
3: {
title : 'This is the third article',
content : 'Making information transferrable. Identifiable. Manipulatable.'
}
},
numArticles : function(){
var size = 0, key;
for (key in this.article){
if(this.article.hasOwnProperty(key)) size++;
}
return size;
},
buildInterface : function(){
var aSize = this.numArticles();
for(var i = 0; i < aSize; i++){
$('body').append('<article><h2>' + this.article[i].title + '</h2></article>');
}
}
}
the buildInterface() function is not able to access the 'article' array in this scenario.
Here is an example of this in progress:
http://jsfiddle.net/merk/xV2n6/41/
Any help here would be appreciated -
I have a hunch it may be a scoping issue - hopefully it is not something related to JSFiddle -
Thanks a ton -
Peace
Mark
articleas an array, why not make it an actual array? You'd getlengthfor free, so you wouldn't need numArticles.