Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways to write JavaScript?

Shulou Source: shulou.com Published: 2022-06-02 13:42:54 10月03日 Update

This article mainly explains "what are the ways to write JavaScript". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the ways to write JavaScript"?

Direct initialization method

Advantages:

1. UserData itself is an object instance. Instantiate a class when it comes up, and I'm not afraid that the browser can't stand it.

2. The code is compact.

3. High programming efficiency.

Disadvantages:

1. The reusability of the code is poor.

2. It does not accord with the idea of object-oriented programming. This kind of thing, design patterns, is often played around on classes. It's hard to use it directly on the object.

Summary: you should avoid using this method to create custom objects.

Use case: QQ mini pop-up window

Construction function method

How to use: you need to create an instance using "new and constructor".

Advantages:

Memory is allocated only when new is used. Without new, browsers will never give you memory resources. If you want it, ignore her if you don't want it!

Object expression

It is similar to the direct initialization method. It's actually a variety.

The red part above makes people dizzy. Anyone who reads this code will probably vomit blood wildly!

Anonymous function method

Thank you for your reading, the above is the content of "what is the JavaScript writing method?" after the study of this article, I believe you have a deeper understanding of what JavaScript writing method has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Writing objects code functions examples learning advantages memory content that is ideas methods browsers programming dizziness compactness usage unbearable variants Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MariaDB OPPO Reno macOS