I’m new to javascript, so some of the existing answers on StackOverflow confused me.
If I have a static class inside of a dynamic class (like below). How can I access variables inside the dynamic class?
function ListItem() = {
var myItem = function() { return "something" };
...
ItemDropdown = function(){
show : function (){
//Want to access the ListItem's myItem here
alert(super.myItem() + "dropdown menu");
}
}
}
var foo = new ListItem();
foo.ItemDropdown.show();
If you want
ItemDropdownto be a method ofListItem, you need to declare it usingthis.With the way you have
myItemdefined, you can just call it by itself.You also have a couple syntax errors:
and
So, you end up with this: