We have used the prototype property in the first chapter to simulate the implementation of classes and inheritance. The prototype property is essentially a JavaScript object. And each function has a default prototype property.
If this function is
Copy Code code as follows:
First create the parent class
function person (name, age, address) {
THIS.name = name;
This.age = age;
this.address = address;
}
To create a child class
function Student (score) {
This.score = score;
The
The basic structure of a single case pattern:
Copy Code code as follows:
Mynamespace.singleton = function () {
return {};
}();
Like what:
Copy Code code as follows:
Mynamespace.singleton = (function () {
1. Object posing asRationale: Constructors Use the This keyword to assign values to all properties and methods (that is, the constructor method declared by the class).
Because the constructor is just a function, you can make the ClassA constructor a
As follows:
Copy Code code as follows:
function Student ()
{
Defines a field in the class student and assigns an initial value, but the access rights for this field are public
This.studentno = ' s001 ';
This.studentname = '
Mode type: Factory mode
Pattern Description: One of the common patterns used to create objects dynamically
Scope of application: Classes that need to be selected in a series of interchangeable subclasses during run time
Note: interface
1, jquery
Gets the value
$ ("#ddlSubmodel"). Val ();
Gets the text value
$ ("#ddlSubmodel"). Find ("option:selected"). Text ();
2. javascript
Gets value value
document.getElementById ("Ddlsubmodel"). Value;
Gets the text value
var
So it is necessary to give an example here for the students:
JavaScript Object-Oriented code example
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Copy Code code as follows:
The car factory of the 60 's
var ocar=new Object;
Ocar.color= "BLACK";
ocar.doors=2;
ocar.pinpai= "Liberation";
Ocar.showpinpai=function ()
{
alert (This.pinpai);//need a production line, production of a car,
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
JavaScript two-object-oriented writing methods and differences
Http://www.jb51.net/article/13211.htm
JavaScript Introduction to the object-oriented compact
Although it is difficult to learn at the beginning, but as long as the understanding, it is very convenient and meaningful to determine. JavaScript also provides this keyword, but it's much more "confusing" than the classic Oo language.
Here's a
All constructors are objects, not all objects are constructors. Each constructor has a prototype property that implements the prototype inheritance and shared properties. object is created with a new expression, for example, new string ("a string")
First: Use the This keyword
function Class1 ()
{
This.onclick = function (e)
{
for (Var i=0 i {
var a = new Date ();
}
}
}
Using this. method provides the flexibility to add properties and methods to an object, and is similar to most OOP
See effects after specific features run
Add F1 Add F2 Add F3 Remove F1 Remove F2
Removing f3
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
[Ctrl + A
javascript click Insert Text Cloud Habitat Community tips, Click on any part of the text to insert a few specified characters, do not believe to try ~
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh
Test Application Testjavascript.mxml
Copy Code code as follows:
Xmlns:s= "Library://ns.adobe.com/flex/spark"
xmlns:mx= "LIBRARY://NS.ADOBE.COM/FLEX/MX" >
Private Function Openwindow (pageurl:string,pagename:string): void{
var
First type:
function person ()
{
this.username = new Array ();
This.password = "123";
}
Person.prototype.getInfo = function ()
{
alert (this.username + "," + This.password);
}
var p = new person ();
var p2 = new Person ();
P.username.push
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