JavaScript Object-oriented (learning and understanding)

Source: Internet
Author: User

The variables created in JS are basically as follows:

var name = ' Saodiseng '; var email = ' [email protected] '; var website = ' http://www.cnblogs.com/saodiseng/';

What if the above is changed to a variable to write? Be bold and reinvent yourself:

var saodiseng = {        name:' Saodiseng ',        email:' [email protected] ',       Website:' http://www.cnblogs.com/saodiseng/'};

Below, I can access it in this way:

The way it looks like a member.
Saodiseng.name;saodiseng.email;saodiseng.website;

This seems to be a hash map of the way (to tell you the truth, hash map is what, I really do not know)
saodiseng["Name"];
saodiseng["email"];
saodiseng["website"];

If we write a function, we usually write "

var function () {alert ("This is a function");};

So, here's what we can write about:

var function () {var hello = "Hello, I am" + this.name
+ ", my email is:" + this.email
+ ", my personal blog address is:" + this.website;

alert (hello);
}

Dazhaohu;

If it's more normative, look at the more pressing wording:

var function (name. email, website) {this.name = name;
This.email = email;
This.website = website;

this. Dazhaohu = function () {
var hello = "Hello, I am" + this.name
+ ", my email is:" + this.email
+ ", my personal blog address is:" + this.website;
alert (hello);
};
};

var Saodiseng = new Person (' saodide ', ' [email protected] ', '
http://www.cnblogs.com/saodiseng/ ");
Saodiseng.dazhaohu ();

JavaScript Object-oriented (learning and understanding)

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.