Home > Web Front-end > Front-end Q&A > what is javascript instance

what is javascript instance

藏色散人
Release: 2021-10-14 14:06:46
Original
3172 people have browsed it

An instance is a concrete product of a class, a real object of a class, and an object is a content structure with multiple attributes; there is no class syntax in JavaScript, so the concept of a class is to create a Object is implemented.

what is javascript instance

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

Instance is the real object of a class. For example, we are all "human beings", and you and I are both instances of the "human" class. Instantiation is the process of creating an object, created with the New keyword.

What is a javascript instance?

In written language, examples are actual examples.

In computer languages, a "class" is called an "instance" after instantiation. "Classes" are static and do not occupy process memory, while "instances" have dynamic memory. In a database, represents a collection of programs. For example, in Oracle, instances are database programs that can support the operation of the database.

Example:

function start(){
   alert("Bang!!!");
}
  
//constructor
function Car(color, title){
   this.color = color;
   this.title = title;
   this.start = start;
}
 
var obj = {a;1,b:2};
var car1 = new Car("red", "BMW");
var car2 = new Car("yellow", "VOIS");
Copy after login

car1 and car2, both of which are instances. The simple understanding of the example is the finished product. For example, cake. Car is the constructor, which can be understood as a cake mold.

The difference between instances and objects, from a definition point of view:

1. An instance is a concrete product of a class,

2. An object is a product with multiple attributes. Content structure.

Instances are all objects, but not all objects are instances.

There is no syntax for classes (before ES6) in JS, so the concept of a class is realized by creating an object.

Recommended study: "javascript basic tutorial"

The above is the detailed content of what is javascript instance. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template