I have two jquery click functions that sets and retrieves value from a javascript object.
var poly;
$( document ).ready(function() {
//save drawing
$("#save").click( function () {
poly = new Polygon();
poly.savedrawingaspoly(map.polygonevent);
poly.tract = tract;
poly.name = $('#polyname').val();
console.log(poly);
});
$("#btnClear").click(function () {
console.log(poly);
//poly.clearplot();
});
});
the console.log(poly); in $("#save").click works. the console.log(poly); in $("#btnClear").click returns undefined. How do I spread the scope of the variable, so the second one can see the variable? Thanks.
polywithout defining it (you do not assign a value topoly). So if you clickbtnClearbeforeSave, you'll getundefined. Inside theSaveclick callback, you assignnew Polygon()topolyso it works fine.