Method 9 of javascript writing

Source: Internet
Author: User

9. YUI Writing Method
YUI 2.7.0 is introduced here. You only need to introduce yahoo. js. YUI introduces namespaces, similar to java packages. The following yahoo tool function package

  • YAHOO. namespace
  • YAHOO. lang
  • YAHOO. lang. hasOwnProperty
  • YAHOO. lang. extend
  • YAHOO. lang. augment
  • YAHOO. log
  • YAHOO_config and YAHOO. env
  • YUI Module Names
Write method:
Copy codeThe Code is as follows:
// Define the package name
YAHOO. namespace ("test ");

// Define a class
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

// Test whether instanceof and p. constructor correctly point to YAHOO. test. Person.
Console. log (p instanceof YAHOO. test. Person );
Console. log (p. constructor = YAHOO. test. Person );

It can be seen that besides the package name, there is no difference with the third write method.

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.