简体   繁体   中英

Variables undefined in backbone.js

I'm been having some trouble playing around with the backbone.js library recently - namely the variables that I instantiate (both an extended View and Model) remain undefined.

Here's some code to show you what I mean:

<script type="text/javascript">
$(document).ready(function(){

var img = new ImageUrl();
var search = new ImageSearchDialogue({el: '.imageUrl', model: img}).render();


});
</script>

Here's the script that I've placed in the HTML document - both variables are undefined however. (I've checked with Firebug)

Is this a scoping issue perhaps?

Is it that you're expecting the variables to be defined globally? They're currently only defined in the scope of the function. Try this:

window.img = new ImageUrl();
window.search = new ImageSearchDialogue({el: '.imageUrl', model: img}).render();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM