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.
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");
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!