Reputation: 26650
This code:
var doc = {
foldPrompt: function(folded) {
return folded ? "Click to unfold" : "Click to fold"
},
createFoldButtons: function() {
var prompt = foldPrompt(true); //The error is here
$("#ComparisonTable td.secrow").each(function(index, td){
$(td).prepend($('<img src="minus.gif" class="foldbtn" alt="'+prompt+'" title="'+prompt+'">'));
});
}
}
gives me an error: Undefined variable: foldPrompt
What am I doing wrong?
Upvotes: 0
Views: 46
Reputation: 169018
foldPrompt
is not a variable; it's a property of doc
, and you need an object reference to access properties of that object.
If someone calls doc.createFoldButtons()
, then the this
context variable will point at the same object that the doc
variable does. So, replace foldPrompt(true)
with this.foldPrompt(true)
.
Upvotes: 2