Object-Oriented Programming in javascript (class-based structuring) (Tip 5)

Source: Internet
Author: User
Regardless of whether java, c #, or vb is used to construct a pair. classobj = new classobj () can be used () the method constructs a class, and then uses the attention and method. In fact, javascript can also be implemented.
Example: Create a js file and define an object EmcObj
1> definition structure creation function EmcObj = function (w, h)
{
This. xWidth = w;
This. yHeight = h; // this table class private changes
}

2> defining methods
 

EmcObj. prototype. _ Init = function ()
{
This. config = {
Render: "AUTO ",
LinkType: "M ",
LinkColor: "blue ",
NodeColor: "# CCCCFF ",
};
// Use this. config. nodeColor to obtain the token value.
} ECOTree. prototype. toString = function (){
Var sl = [];
Sl. push ("<div name = abc> ");
Sl. push ("</div> ");
Return sl. join ('');
}

3> define this. config. name = "aa"; // this will do.

Using Method var emc
Function CreateEmcObj ()
{
Emc = new EmcObj (100,100 );
Document. write (emc. tostring ());
}

Function CreateInit ()
{
Emc. _ init ();
}

OK

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.