Creating a reference to a variable inside another property
I am passing the variable evtID which is inside the vars object, into
click event inside the createEvent method. I have to reference it using
cal.vars.evtID, I was wondering if there is anyway to pass this as
reference another variable to make the amount of typing shorter?
Basically I don't want to have to type cal.vars.variable name for every
variable I create in the vars object.
var cal = {
vars: {
evtID: 0 // here
},
createEvent: function(){
$('.square').on('click',function(){
var array = [
'<div class="event" id="event' + cal.vars.evtID + '">', //
and here
'<div class="close"></div>',
'</div>'
];
$('.event-container').append(array.join(""));
cal.vars.id++;
});
},
init: function(){
this.createEvent();
}
}
window.onload = function(){
cal.init();
}
No comments:
Post a Comment