9、YUI的写类方式 这里引入的是YUI 2.7.0版,只需引入yahoo.js。YUI引入了命名空间,类似于java的包。以下yahoo的工具函数包
YAHOO.namespace
YAHOO.lang
YAHOO.lang.hasOwnProperty
YAHOO.lang.extend
YAHOO.lang.augment
YAHOO.log
YAHOO_config and YAHOO.env
YUI Module Names 写类方式: 复制代码 代码如下://定义包名 YAHOO.namespace("test"); //定义类 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;} //创建一个对象 var p = new YAHOO.test.Person("jack"); console.log(p.getName());//jack p.setName('tom'); console.log(p.getName());//tom //测试instanceof及p.constructor是否正确指向了YAHOO.test.Person console.log(p instanceof YAHOO.test.Person); console.log(p.constructor == YAHOO.test.Person);可以看出除了多了包名,与第三种写类方式 并无区别。
推荐阅读
javascript scrollLeft,scrollWidth,clientWidth,offsetWidth 完全详解
scrollHeight: 获取对象的滚动高度。 scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 scrollWidth:获取对象>>>详细阅读
本文标题:javascript 写类方式之九
地址:http://www.17bianji.com/kaifa2/JS/28478.html
1/2 1