JS Member notes

Source: Internet
Author: User

 


/**/ /*
Patterns Mode
Public
Function Constructor ()
{
This. membername = value;
}
Constructor. Prototype. membername = value;

Private
Function Constructor ()
{
VaR self = this;
VaR membername = value;
Function membername (){}
}

Note: The function statement
Function membername (){}

Is shorthand
VaR membername = function membername (){};

Privileged privilege a privileged method can access private variables and methods while being visible to public domains. You can also delete or replace a privileged method, but cannot change it.

The privileged method is assigned in the constructor using this.

Function Constructor ()
{
This. membername = function ()
{
Self. membername;
};
}

Static
Constructor. method = function ()
{
This. member;
}

Add public method;
This technique is generally used to add public methods. When a member is retrieved and not found in the object, it obtains it from the prototype member of the object constructor.
This prototype mechanism can be used to implement inheritance. It also saves the memory. To add a method to all objects generated by a constructor, add the function to the prototype of the constructor:
Container. Prototype. mymethod = function ()
{
This. member;
}


*/

// Class mystring
Function Mystring (STRs)
{
VaR _ STR = STRs; // Private field;
This . Str = _ STR; // Public Field


// Public Method
This . Lefttrim =   Function (Start)
{
RET=Lefttrim (This. STR, start); // This = new mystring (STRs );
ReturnRET;
}

// Private Method
Function Lefttrim (STR, start)
{
If (Str. Length > 0   && Str. indexof (start) = 0 )
{
Str=Str. substring (start. length, str. Length );
Str=Lefttrim (STR, start );
}
Return STR;
}

This . Righttrim =   Function (End)
{
RET=Righttrim (_ STR, end );
Return ret;
}

Function Righttrim (STR, end)
{
If (Str. Length > 0   && Str. lastindexof (end) = Str. Length - End. length)
{
Str=Str. substring (0, Str. Length-End. Length );
Str=Righttrim (STR, end );
}
Return STR;
}

VaR Self =   This ;
This . Trim =   Function ()
{
Str=Righttrim (self. lefttrim (" "),"");

Return Str;
}
}

// Static Method
Mystring. lefttrim =   Function (STR, start)
{
If (Str. Length > 0   && Str. indexof (start) = 0 )
{
Str=Str. substring (start. length, str. Length );
Str= This. Lefttrim (STR, start );

}
Return STR;
}

Mystring. righttrim =   Function (STR, end)
{
If (Str. Length > 0   && Str. lastindexof (end) = Str. Length - End. length)
{
Str=Str. substring (0, Str. Length-End. Length );
Str= This. Righttrim (STR, end );
}
Return STR;
}
// End Class mystring

Mystring. Prototype = new string ();

Function Vr3d ()
{
// This. vr3d () = function (){}
This . Name;
This . Changename =   Function (Name)
{
This. Name=Name;
}
This . Url;
This . Seturl =   Function (URL)
{
This. Url=URL;
}
This . Geturl =   Function ()
{
If(This. Url)
Return This. Url;
Else
Return "";
}
}

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.