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.