Optimisation #2 Javascript : Réduction du nombre de variables globales

En créant un nouvel objet (et un seul!), on évite de créer pleins de variables globales.

On gagne donc en :

Propreté de code
Performance (très peu avec les navigateurs actuels)

Et surtout, on évite les conflits de noms avec d’autres applications, widgets et librairies!

BAD

[javascript]
var firstName = ‘Joey’;
var lastName = ‘Bronner’;
function sayHello() {

}
console.log(firstName);
[/javascript]

GOOD

[javascript]
var User = {
firstName : ‘Joey’,
lastName : ‘Bronner’,
sayHello : function() {

}
}
console.log(User.name);
[/javascript]

25 Comments Optimisation #2 Javascript : Réduction du nombre de variables globales

  1. dịch vụ marketing tổng thể

    996865 611772Hello, Neat post. There is an problem along along with your internet site in internet explorer, could test thisK IE nonetheless will be the marketplace leader and a huge portion of other folks will miss your magnificent writing because of this problem. 424943

    Reply
  2. 먹튀검증

    489552 170476Oh my goodness! a fantastic post dude. Thanks Nevertheless My business is experiencing issue with ur rss . Dont know why Not able to sign up for it. Possibly there is any person obtaining identical rss difficulty? Anyone who knows kindly respond. Thnkx 790472

    Reply
  3. ทางเข้า SBOBET

    668324 898203Youre so cool! I dont suppose Ive read anything in this way before. So nice to uncover somebody with some original concepts on this topic. realy appreciate starting this up. this exceptional site is something that is needed more than the internet, a person if we do originality. valuable work for bringing something new towards the web! 922117

    Reply
  4. Kristina

    I’m not sure exactly why but this website is loading very slow for me.
    Is anyone else having this problem or is it
    a problem on my end? I’ll check back later on and see if the problem still
    exists.

    Reply
  5. Sommer

    I’ve learn several just right stuff here.

    Certainly value bookmarking for revisiting. I wonder
    how a lot effort you set to make this type of great informative website.

    Reply

Leave a Reply

Your email address will not be published.