Learn jquery from scratch (Theatre edition) You must know the JavaScript

Source: Internet
Author: User
Tags access properties

I. Summary

This is the theater version of the jquery series, which has nothing to do with the main line of jquery, and introduces some of the JavaScript details that you would normally overlook. For developers who want to consolidate JavaScript's theoretical knowledge and basic knowledge.

Two. Foreword

Recently interviewed some people, found that even experienced developers, for some basic theories and details are often blurred. Writing this article is because the first time I learned the following content, I found that I do have a harvest and understanding. In fact, we can easily ignore the details of JavaScript and more, this article is only the tip of the iceberg. I hope everyone can get a good through this article.

Three. JavaScript Object-oriented

JavaScript is an object-oriented language, although many books are explained, but there are many novice developers do not understand.

Creating objects

PS: Previously wrote a detailed article on the creation of objects (prototype method, factory method, etc.) but could not find, look back if you can find me to add in. The following is simply described.

In C # We use the New keyword to create objects, and we can use the New keyword in javascript:

var objectA = new Object();

But actually "new" can be omitted:

var objectA = Object();

But I recommend that you always declare an object with the New keyword to keep the grammar.

Create attributes and assign values

Attributes are not required to be declared in JavaScript and are created automatically when assigned:

objectA.name = "my name";

Access Properties

Generally we use the "." To access the properties of an object hierarchically:

alert(objectA.name);

Nested properties

The properties of an object can also be any JavaScript object:

var objectB = objectA;
objectB.other = objectA;
//此时下面三个值相当,并且改变其中任何一个值其余两个值都改变

objectA.name;
objectB.name;
objectB.other.name;

Using indexes

If there is a property name "School.college" on the objecta, then we cannot pass "." Access because the "ObjectA.school.college" statement refers to the College property of the school Property object that is looking for objecta.

In this case we need to set and access the properties through the index:

objectA["school.college"] = "BITI";
alert(objectA["school.college"]);

The following statements are equivalent:

objectA["school.college"] = "BITI";
var key = "school.college"
alert(objectA["school.college"]);
alert(objectA["school" + "." + "college"]);
alert(objectA[key]);

Related Article

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.