Passing jQuery object property to function
new $.Feed({
container: "#us-feed",
feedUrl: "http://www.somefeed.com/feed/",
onFeedLoad: function(feedResult) {
formatFeed(feedResult);
}
开发者_如何学Python});
Pretty basic syntax question: what is the syntax to pass the container
property to the formatFeed function for use as a variable?
You can reference the current object with this:
new $.Feed({
container: "#us-feed",
feedUrl: "http://www.somefeed.com/feed/",
onFeedLoad: function(feedResult) {
formatFeed(feedResult, this.container);
}
});
As mentioned in the comments, that depends a lot on where and how onFeedLoad is being called. If you want a safe solution just store the container text in a temporary variable as mcos already suggested:
var container = "#us-feed";
new $.Feed({
container: container,
feedUrl: "http://www.somefeed.com/feed/",
onFeedLoad: function(feedResult) {
formatFeed(feedResult, container);
}
});
精彩评论