JS Object Note

Source: Internet
Author: User

#编程范式

# #1, Imperative
-Process oriented
-Object-oriented (oo,object-oriented)

# #2, declarative
-DSL: As long as expected results (for example: HTML, CSS)
-Functional: No side effects to solve concurrency problems


#js中对象
-Native: Compliant with ES (ECMASCRIPT) specification
-Built-in: with ES internally provided
-Host: Browser-dependent objects (BOM)
# # #类
Object-oriented language a flag, a collection of objects with the same properties and methods, is an abstraction of an object (an object is an instance of a class).

# # #js中没有类的概念, each object is based on a prototype (a prototype is also an object):
* * Object → prototype →object→null**

Add properties and methods on the prototype chain (object. Prototype can access its prototype) the objects that follow will "inherit" the properties and methods that you added

#对象的创建
# #对象字面量 (syntactic sugar: unique, does not need to be duplicated)
Example:


var person={
Name: "Zhang San",
Age:12,
Sayhi:function () {
Alert ("I Am" +this.name+ "Hello!! ");
}
}


Creating multiple objects like this can be cumbersome and creates duplicates!!!

# #构造函数 (Similar to Class) + prototypes
Example:

declaring constructors
Let Student=function (A (parameter) ...) {
This.name=a;
This.sayhi=function () {
Alert ("I Am" +this.name+ "Hello!! ");
}
}
Creating objects
Let student1=new (emphasis) Student ("Sanmao");


Access prototypes:
Student.prototype.sayhi=function () {
Alert ("I Am" +this.name+ "Hello!! ");
}
This way, the future of the object will have this method!!

# #访问对象属性
# #. operator
-For the (.) operator, the right side must be a simple identifier named after the property name, and the identifier must appear directly in the program, not the data type, and therefore cannot be modified.

var Author=book.author;
var name=author.name;


###[] Operator
-For the ([]) operator, the square brackets must be an expression that evaluates to a string, which is the property name. Strings are JS data types, so they can be modified and created when the program is run.

var author=book[' author '];

for (let i=0;i<4;i++) {
addr=person[i+ "Name"];
}


For-in can be used to iterate over the properties of an object, but the method simply iterates over the enumerable property
The methods defined by the JS core are non-enumerable, such as ToString (). However, the properties defined in the code are enumerable (can be defined as non-enumerable by special)


For (let K in person) {
PERSON[K];
}

JS Object Note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.