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)