[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:
parent
691a6b48d2
commit
3bbb11353a
|
@ -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.$element.html(QWeb.render("GraphView", {"fields_view": this.fields_view, "chart": this.chart,'view_id': this.view_id}));
|
||||||
this.opration_fld = {};
|
this.opration_fld = {};
|
||||||
if (result.length){
|
if (result.length){
|
||||||
for(res in result) {
|
for(var res in result) {
|
||||||
for(fld in result[res]) {
|
for(var fld in result[res]) {
|
||||||
if (typeof result[res][fld] == 'object') {
|
if (typeof result[res][fld] == 'object') {
|
||||||
result[res][fld] = result[res][fld][result[res][fld].length - 1];
|
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];
|
var gen_key = result[i][this.chart_info_fields]+"_"+result[i][this.group_field];
|
||||||
if (this.opration_fld[gen_key] == undefined){
|
if (this.opration_fld[gen_key] == undefined){
|
||||||
var map_val = {}
|
var map_val = {}
|
||||||
|
@ -182,7 +182,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
|
||||||
if (xystr[xystring] == undefined){
|
if (xystr[xystring] == undefined){
|
||||||
xyname = {};
|
xyname = {};
|
||||||
xyname[self.chart_info_fields] = xystring;
|
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[self.group_list[j]] = 0.0001;
|
||||||
}
|
}
|
||||||
xyname[newkey] = result[i][self.operator_field];
|
xyname[newkey] = result[i][self.operator_field];
|
||||||
|
@ -207,7 +207,7 @@ openerp.base_graph.GraphView = openerp.base.Controller.extend({
|
||||||
|
|
||||||
//for legend color
|
//for legend color
|
||||||
var grp_color = [];
|
var grp_color = [];
|
||||||
for (i in self.group_list){
|
for (var i in self.group_list){
|
||||||
var legend = {};
|
var legend = {};
|
||||||
if (self.group_list[i] == "val"){
|
if (self.group_list[i] == "val"){
|
||||||
legend['text'] = self.fields[self.operator_field]['string']
|
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:
|
||||||
|
|
|
@ -16,6 +16,43 @@ Source code repository
|
||||||
Merge proposals
|
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
|
Writing documentation
|
||||||
+++++++++++++++++++++
|
+++++++++++++++++++++
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue