JavaScript writing class nine _js object oriented

Source: Internet
Author: User
9, Yui writing class way
Here is the introduction of Yui 2.7.0 version, just introduce Yahoo.js. Yui introduced a namespace, similar to the Java package. The following Yahoo Tools function pack
    • Yahoo.namespace
    • Yahoo.lang
    • YAHOO.lang.hasOwnProperty
    • YAHOO.lang.extend
    • YAHOO.lang.augment
    • YAHOO.log
    • Yahoo_config and Yahoo.env
    • YUI Module Names
Write Class Way:
Copy Code code as follows:

Define Package Name
Yahoo.namespace ("test");

Defining classes
YAHOO.test.Person = function (name) {
THIS.name = name;
}
YAHOO.test.Person.prototype.setName = function (name) {this.name = name;}
YAHOO.test.Person.prototype.getName = function () {return this.name;}


Create an Object
var p = new YAHOO.test.Person ("Jack");

Console.log (P.getname ());//jack
P.setname (' Tom ');
Console.log (P.getname ());//tom

Tests whether instanceof and p.constructor correctly point to the YAHOO.test.Person
Console.log (P instanceof YAHOO.test.Person);
Console.log (P.constructor = = YAHOO.test.Person);

You can see that in addition to the package name, there is no difference from the third way of writing a class.
Related Article

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.