javascript - Best practice for defining variables in a Backbone view -



javascript - Best practice for defining variables in a Backbone view -

i have backbone view has deal lot of logic. i'm using require.js , wondering best way of creating variables view. current set so.

define([ 'jquery', 'underscore', 'backbone', 'pixi', 'tweenlite', 'easepack', 'app/models/tower-item-model', 'app/views/tower-item-view', 'app/templates' ], function($, _, backbone, pixi, tweenlite, easepack, toweritemmodel, toweritemview, templates){ 'use strict'; // ********* create view variables ************ var numberoftowers = 1; // set icons in top right of view. default 1 var sectionwidth = 180; var mmtopixelratio = 180/300; var currentwidth = 0; var currentheight = 0; var currentdepth = 0; var framecolourpressed = false; var hiliteintensity = 0; var hiliteup = true; var hiliteintervalid; var towerview = backbone.view.extend({ id: 'tower-view', classname: 'tower-view',

am right in thinking these variables in global namespace? if imagine not good. had view set , app creating several instances of it. noticed alter in 1 of variables 1 instance affecting of them.

is there simpler way of declaring variables true instance variables?

many thanks

you can add together variable in view class

for example,

var towerview = backbone.view.extend( { id: 'tower-view', classname: 'tower-view', currentwidth : 0, currentheight : 0, currentdepth : 0, framecolourpressed : false, settowerheight : function() { console.log(this.currentwidth); } });

these called true class variables, , different each instance.

javascript backbone.js requirejs

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -