0

I'am doing somtehing like this

Client.Selectors = {
    var cfg = null;
    Init:function(config){
       ...
       cfg = config;
       ...
    },
    Close:function(){
    }
};

And on the debugger of chrome I got this error :

Uncaught SyntaxError: Unexpected identifier

I don't know why

nicosantangelo
  • 13,216
  • 3
  • 33
  • 47
jcvegan
  • 3,111
  • 9
  • 43
  • 66
  • 1
    Be careful with the notation, in javascript a capitalized variable is a constructor. If you're not declaring a constructor you should use camelCase with the first letter in lowercase. – nicosantangelo Feb 20 '12 at 05:26
  • @Nicosunshine That's only a convention and not a language feature. See http://stackoverflow.com/questions/1564398/javascript-method-naming-lowercase-vs-uppercase – Phil Feb 20 '12 at 22:40
  • @Phil that was what I ment :), didn't realize that sounded like a language feature. – nicosantangelo Feb 20 '12 at 22:47

3 Answers3

3
var cfg = null;
Client.Selectors = {
    Init:function(config){
       ...
       cfg = config;
       ...
    },
    Close:function(){
    }
};
ironchefpython
  • 3,409
  • 1
  • 19
  • 32
2

You have problem here:

var cfg = null;

Should be:

cfg : null,

Since you are using object literal notation. So = changed to : and ; changed to ,.

Client.Selectors = {
    cfg : null,
    Init:function(config){
       this.cfg = config;
    },
    Close:function(){
    }
};

Learn More:

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
0

You are declaring Selectors with the object literal notation and as such the syntax is

some = {
    identifier:value,
    id2:function() {}
}

and all the properties are accessible from the outside.... you may want to consider using a constructor function to encapsulate your cfg

some = function() {
   var privateVar = "something";

   return {
      init: function() {
         alert(privateVar);
      }
   }

}
Jaime
  • 6,736
  • 1
  • 26
  • 42