google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






5 habitudes JavaScript Bon pour une meilleure am?lioration Ce tutoriel montre JavaScript article complet liste d?taill?e de 5 habitudes JavaScript bon que les d?veloppeurs JavaScript , JavaScript codeurs et programmeurs JavaScript doit suivre pour am?liorer des comp?tences en programmation JavaScript , ainsi que les applications JavaScript et JavaScript performance S'il vous pla?t aller ? la page int?rieure post pour plus de d?tails et des instructions


Gratuit iPage h�bergement Web pour la premi�re ann�e MOMENT



Si vous �tes toujours � la recherche d'un fournisseur d'h�bergement Web fiable avec des tarifs abordables, pourquoi vous ne prenez pas un peu de temps pour essayer iPage, seulement avec $1.89/month, inclus $500+ Cr�dits suppl�mentaires gratuites pour le paiement de 24 mois ($45)?

Plus de 1.000.000 de clients + existisng peuvent pas avoir tort, vraiment vous n'�tes pas aussi! Plus important encore, lorsque vous enregistrez l'h�bergement web � iPage gr�ce � notre lien, nous allons �tre heureux de renvoyer un plein remboursement. C'est g�nial! Vous devriez essayer iPage h�bergement web GRATUITEMENT maintenant! Et contactez-nous pour tout ce que vous devez savoir sur iPage.
Essayez iPage GRATUIT premi�re ann�e MOMENT

Javascript gets a bad rap on the Internet, but there are few languages that are so dynamic, so widespread, and so deeply rooted in our lives as Javascript is. The low barrier of entry leads some people to call it a script kiddie language, others scoff at the concept of a dynamic language while riding their statically typed high horse. You and Javascript just got off on the wrong foot, and now you've made it angry. Here's five reasons why your Javascript code sucks.

1. You're not using a namespace.

Remember in college when the teacher said you can't use global variables in your homework? Using globals in Javascript is no different. Web pages tend to be soups of aggressively pasted scripts and modules from every corner of the Internet. If you're using a variable named loader() you're just asking for a Javascript smack down. If you unwittingly over write a function, Javascript's not going to complain. You called it a script kiddy language, remember? That means you know what's going to happen when you do this.

function derp() { alert("one"); } function derp() { alert("two"); } derp();

Two, the answer is two. It didn't have to be. It could have been one. Namespacing all of your code is good manners, and it's easy to do. Here's an easy way to namespace.

var foospace={}; foospace.derp=function() { alert("one"); } function derp() { alert("two"); } foospace.derp();

2. You're a magician, creating variables out of thin air.

Using magic numbers is a no-no. Finding a seemingly arbitrary number in the middle of a 40 line block of code is a maintenance nightmare. Declaring a variable for the first time in a 40 line block of code is just as much of a scare. When you come across one you may ask yourself, "where was this declared?" and quickly mash Ctrl+F in a mad fit to find the variable's original source. No, instead, it was a Javascript abuse, more of a trick than a magic trick. Always declare your variables at the top of their scope. Just because you don't have to, doesn't mean you shouldn't.

function() { var a, //description b; //description //process... }

3. You don't understand variable scope in Javascript.

You're a brilliant programmer, you eat C++ code for lunch and poop Lisp. You know what variable scope is, you have full control over your variables and watch them like an overlord. Then Javascript put a metaphorical laxative in your coffee and had a good laugh.

var herp="one"; { var herp="two"; } alert(herp);

The value of herp in this case is not one, it's two. Javascript variable scope is not dependent on blocks like other languages. Javascript variable scope is function based. Each function has its own scope, Javascript is far too cool to concern its self with meaningless curly braces. In fact, Javascript is so cool that it will let you pass scope around like any other namespace or variable.

4. You think Javascript OOP is a tack on.

Javascript, from the ground up, is an object oriented language. Everything in Javascript is an object, everything! Even literals like integers and strings are implicitly converted to objects with their built in constructors. The difference Javascript has when compared to other object oriented languages is that it lacks classes. Javascript objects are defined as functions, and even functions themselves are objects. Javascript has a property named prototype inherent in all objects that lets you mutate the structure of objects and decorate them with more variables and functionality.

var derp; // will hold a Herp instance var Herp= function() { this.opinion="Javascript is cooler than BASIC."; } Herp.prototype.speak=function() { alert(this.opinion); } var derp= new Herp(); derp.speak();

If this looks foreign to you, I'd like to introduce you to my good friend Google. Google is good at helping people learn about things. OOP is way too big of a topic for my short, comically condescending, numbered list. If you need help finding Google try using your favorite search engine.

5. You're using the new keyword like a blind guy with a cross bow.

Javascript must be your first girlfriend, because you have no idea how to use that thing. If you want to please Javascript like a real man you're going to need to learn about object literals. With the exception of instantiating objects, and some rare cases where you need lazy data loading, you probably shouldn't be using the new keyword. Allocating lots of new variables is slow in Javascript, and you'll always get better performance using object literals.

var rightway= [1, 2, 3]; var wrongway= new Array(1, 2, 3);

Remember all that talk about Javascript scope being function based? Remember someone mentioning that Javascript objects are defined as functions? Not using the new keyword when instantiating an object will blow your mind as it sets the scope of the object to the global namespace. It's good habit to always instantiate objects with new.

var derp="one"; var Herp=function() { this.derp="two"; } var foo=Herp(); alert(derp);

Javascript won't complain if you do this, and will actually alert the answer two! There are ways to write objects to prevent this behavior using instanceOf() but a better nine to five solution is to use the new keyword correctly like the professional that you are.

Now that you know why your Javascript code sucks, you can make it suck less by remembering these factoids. Of course, there's other reasons that your Javascript code sucks. I like three space tabs, I prefer underscores to camel case, and I like to capitalize my function names that represent classes. Of course, that's a discussion for another day. There's a lot of reasons why your Javascript code sucks, and probably just as many reasons why mine sucks, so feel free to share, add, agree, or tear me a new one in the comments.

Edit Huge thanks to rogeliorv and Jared Wein for pointing out the error in point five. You guys rock.

AIVideo-App.com
Générez vos vidéos d'entreprise par l'IA avec la voix ou simplement du texte

chatGPTaz.com
Parlez à ChatGPT dans votre langue maternelle

AppAIVidéo
Votre première application vidéo AI GRATUITE

Deepfake Video
Deepfake AI Video Maker

Deepfake
Deepfake AI Video Maker

AI Deep Fake
Deepfake AI Video Maker

AIvidio
AI Video Mobile Solutions

AIvideos
AI Video Platform & Solutions

AIvedio
AI Video App Maker

Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT

Faceswap AI en ligne
Échangez des visages, des vidéos, des photos et des GIF instantanément avec de puissants outils d'IA - Faceswap AI Online GRATUIT

Temu gratuit 500 $ pour les nouveaux utilisateurs
Claim Free Temu $500 Credit via Affiliate & Influencer Program

Crédits publicitaires TikTok gratuits
Maîtrisez les publicités TikTok pour le marketing de votre entreprise

Dall-E-OpenAI.com
Générez automatiquement des images créatives avec l'IA

chatGPT4.win
Parlez à ChatGPT dans votre langue maternelle

Premier produit d'intelligence artificielle d'Elon Musk - Grok/UN.com
Parlez au chatbot Grok AI dans votre langue

Outily.win
Centre d'outils ouvert et gratuit, utilisable par tous et pour tous, avec des centaines d'outils

GateIO.gomymobi.com
Airdrops gratuits à réclamer et à partager jusqu'à 150 000 $ par projet

iPhoneKer.com
Économisez jusqu'à 630 $ à l'achat d'un nouvel iPhone 16

Acheter le robot Tesla Optimus
Commandez votre robot Tesla Bot : Optimus Gen 2 dès aujourd'hui pour moins de 20 000 $

JavaScript par jour


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web