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.