


Analysis of five reasons why your Javascript skills are poor_javascript skills
Its low learning threshold makes many people call it a preschool scripting language. Another thing that makes people laugh at it is that the concept of dynamic language uses high-standard static data types. In fact, you and Javascript are on the wrong side, and now, you are making Javascript very angry. Here are five reasons why your JavaScript skills suck.
1. You are not using namespaces.
Do you remember when your teacher in college told you not to use global variables in your homework? The use of global variables in Javascript is no exception. If you are not careful, Web pages will become chaotic, filled with a mess of mutually infringing scripts and script libraries from all corners of the Internet. If you name a variable loader(), you're asking for trouble. If you overload a function without realizing it, Javascript won't remind you at all. You also called it a preschool programming language, remember? What I'm saying is, you need to know what happens after you do this.
function derp() { alert(“one”); }
function derp() { alert(“two”); }
derp();
“two”, the answer is “two”. It doesn't necessarily have to be this way, it could also be "one". So, it's easy to put all your code in its own namespace. Here's a simple way to define your own namespace.
var foospace={};
foospace.derp =function() { alert(“one”); }
function derp() { alert(“two”); }
foospace.derp();
2. You are doing magic, you are defining variables in one place and one in another.
Using an inexplicable combination of numbers and letters as variable names is a lose-lose outcome. Finding a character variable with no meaning in a 40-line block of code is a maintenance nightmare. Mixing the first declaration of a variable into a 40-line block of code is also a nightmare. Even when you encounter such a variable yourself, you can't help but ask yourself: "Where is this defined?", and then quickly use the Ctrl F combination to find the location where this variable was originally defined in the source code. No, don't do that, on the contrary, it's an abuse of Javascript and a stupid approach. You should always define a variable at the top of its scope. It doesn't mean that just because it's not necessary, you don't have to do it.
function() {
var a, // description
b; //description
//process…
}
3. You do not understand the variable scope of Javascript.
You are a genius programmer. What you eat is C and what you pull is List. You know what variable scope is, you have complete control over your variables, and you watch over them like a king. However, Javascript poops in your coffee and makes you laugh.
var herp=”one”;
{
var herp=”two”;
}
alert(herp);
이 경우 얻는 약초는 "하나"가 아니라 "둘"입니다. Javascript의 변수 범위는 다른 언어와 마찬가지로 코드 블록에 의존하지 않습니다. Javascript의 변수 범위는 함수를 기반으로 합니다. 각 함수에는 고유한 변수 범위가 있으며 Javascript는 이에 대해 훌륭하며 중괄호로 묶인 의미 없는 범위를 무시합니다. 실제로 Javascript는 네임스페이스나 변수와 같은 변수 범위를 전달할 수도 있을 정도로 훌륭합니다.
4. 자바스크립트의 객체지향 기능을 접목한 것이라고 생각하시나요?
자바스크립트는 처음부터 객체지향 언어였습니다. Javascript의 모든 것은 객체입니다. 숫자나 문자와 같은 문자 기호도 고유한 생성자를 통해 객체로 변환될 수 있습니다. 다른 객체지향 언어와 비교하여 Javascript는 클래스가 없다는 점에서 다릅니다. Javascript 객체는 함수처럼 정의되며 함수 자체도 객체입니다. Javascript에는 프로토타입이라는 속성이 있습니다. 이 속성을 사용하여 객체의 구조를 변경하고, 객체를 수정하고, 더 많은 변수를 추가할 수 있습니다.
var derp; 인스턴스
var Herp= function() {
this.opinion=”Javascript는 BASIC보다 더 멋집니다.”
}
Herp.prototype.speak=function() { Alert(this.opinion) ; }
var derp= new Herp();
derp.speak();
이 내용이 귀하에게 중요하지 않은 경우, 저의 좋은 친구인 Google을 소개하고 싶습니다. Google 사람들이 지식을 배우도록 돕는 데 능숙합니다. 객체지향은 나의 짧고 이목을 끄는 기사에 비해 너무 큰 주제입니다.
5. 'new'라는 키워드를 사용하면 눈먼 사람, 눈먼 말과 같습니다.
Javascript가 첫 여자친구임에 틀림없어요. 당황한 것 같으니까요. 실제 사람처럼 자바스크립트를 즐기고 싶다면 객체 표기법을 이해해야 합니다. 개체를 인스턴스화해야 하는 경우나 데이터 로드를 지연해야 하는 드문 경우를 제외하면 기본적으로 new 키워드를 사용할 필요가 없습니다. JavaScript에서 많은 수의 새 변수의 주소를 할당하는 것은 느린 작업이므로 효율성을 위해 항상 객체 표기법을 사용해야 합니다.
var rightway= [1, 2, 3 ];
varwrongway= new Array(1, 2, 3);
제가 Javascript의 변수 범위가 함수를 기반으로 한다고 말한 것을 기억하시나요? 자바스크립트 객체는 함수처럼 정의된다는 말을 아직도 기억하시나요? 객체를 선언하는 데 new 키워드를 사용하지 않으면 객체를 전역 범위로 지정하게 됩니다. 그러므로 객체를 선언할 때 항상 new 키워드를 사용하는 것이 좋은 습관입니다.
var derp=”one”; >var Herp =function() {
this.derp="two";
}
var foo=Herp()
alert(derp)
이제 Javascript 코드가 형편없다는 것을 알게 되었습니다. 위에서 언급한 사항을 기억한다면 코드가 향상될 것입니다. 나는 3개의 탭 키를 사용하여 코드를 들여쓰는 것을 좋아하고 밑줄을 사용하여 단어를 연결하는 것을 좋아하며 함수 이름의 첫 글자를 대문자로 사용하여 객체임을 표시하는 것을 좋아합니다. 물론 이것은 또 다른 논의이다. 제가 형편없는 기술을 많이 갖고 있는 것처럼 여러분의 자바스크립트 코드가 형편없이 작성되는 데에는 여러 가지 이유가 있으니, 댓글로 여러분의 의견을 자유롭게 표현하고, 지지하고, 반대하고, 조언해 주세요.
5번 항목의 오류를 지적해주신 rogeliorv와
Jared Wein에게 깊은 감사를 드립니다. 당신은 강하다.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
