[FIX] non-instance should all be declared with 'var'

See doc for rationale

bzr revid: xmo@openerp.com-20110617090746-z35n4jsdqvicoa9h
This commit is contained in:
Xavier Morel 2011-06-17 11:07:46 +02:00
parent 691a6b48d2
commit 3bbb11353a
2 changed files with 43 additions and 6 deletions

View File

@ -84,8 +84,8 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
this.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id}));
this.opration_fld = {};
if (result.length){
for(res in result) {
for(fld in result[res]) {
for(var res in result) {
for(var fld in result[res]) {
if (typeof result[res][fld] == 'object') {
result[res][fld] = result[res][fld][result[res][fld].length - 1];
}
@ -101,7 +101,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
}
}
for (i in result){
for (var i in result){
var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field];
if (this.opration_fld[gen_key] == undefined){
var map_val = {}
@ -182,7 +182,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
if (xystr[xystring] == undefined){
xyname = {};
xyname[self.chart_info_fields] = xystring;
for (j in self.group_list){
for (var j in self.group_list){
xyname[self.group_list[j]] = 0.0001;
}
xyname[newkey] = result[i][self.operator_field];
@ -207,7 +207,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
//for legend color
var grp_color = [];
for (i in self.group_list){
for (var i in self.group_list){
var legend = {};
if (self.group_list[i] == "val"){
legend['text'] = self.fields[self.operator_field]['string']
@ -381,4 +381,4 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
};
// vim:et fdc=0 fdl=0:
// vim:et fdc=0 fdl=0:

View File

@ -16,6 +16,43 @@ Source code repository
Merge proposals
+++++++++++++++
Coding issues and coding conventions
++++++++++++++++++++++++++++++++++++
Javascript coding
~~~~~~~~~~~~~~~~~
Use ``var`` for *all* declarations
**********************************
In javascript (as opposed to Python), assigning to a variable which does not
already exist and is not explicitly declared (via ``var``) will implicitly
create a global variable. This is bad for a number of reasons:
* It leaks information outside function scopes
* It keeps memory of previous run, with potentially buggy behaviors
* It may conflict with other functions with the same issue
* It makes code harder to statically check (via e.g. IDE inspectors)
.. note::
It is perfectly possible to use ``var`` in ``for`` loops:
.. code-block:: javascript
for (var i = 0; i < some_array.length; ++i) {
// code here
}
this is not an issue
All local *and global* variables should be declared via ``var``.
.. note:: generally speaking, you should not need globals in OpenERP Web: you
can just declare a variable local to your top-level function. This
way, if your widget/addon is instantiated several times on the same
page (because it's used in embedded mode) each instance will have its
own internal but global-to-its-objects data.
Writing documentation
+++++++++++++++++++++