Reputation: 605
I am trying to access properties of a config object from within another object:
var myConfigObj = {
$myCachedSelector: $('#mySelector')
}
var myObj = {
$selector: myConfigObj.$myCachedSelector,
url: 'http://www.someurl.com/somepath'
}
$.each([ myObj, mySecondObj, myThirdObj ], function() {
this.$selector.load(this.url, function(){
//do something
});
When trying to use $selector in the each function then, it returns "undefined". Both objects are in the same scope, and I don't know what the problem is.
Upvotes: 0
Views: 1611
Reputation: 35021
this
in the right-hand "Watch" pane;this
object you're stopped on has a $selector
property which has a load
method then it's not the cause of your problem, so continue round the loop.this
object doesn't have a $selector
property, or has one that doesn't have a load
method, you've found your culprit. Now work out why you are sending it into that loop, or where you are failing to initialise it.Upvotes: 1
Reputation: 137997
This code worked well enough for me, with a few minor tweaks:
This is probably the problem: Firefox is complaining about the semicolon, should be:
var myConfigObj = {
$myCachedSelector: $('#mySelector')
}
$(document).ready
, of course.});
at the end (probably a copy/paste thing)Upvotes: 1