diff --git a/addons/base_graph/static/src/js/graph.js b/addons/base_graph/static/src/js/graph.js index 0c0f9deb629..e1805f2d07a 100644 --- a/addons/base_graph/static/src/js/graph.js +++ b/addons/base_graph/static/src/js/graph.js @@ -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: \ No newline at end of file +// vim:et fdc=0 fdl=0: diff --git a/doc/source/project.rst b/doc/source/project.rst index faa15da2163..80ed0e86143 100644 --- a/doc/source/project.rst +++ b/doc/source/project.rst @@ -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 +++++++++++++++++++++