易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript写类方式之九

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的一些工具

JS Check:
javascriptlint http://www.javascriptlint.com/index.htm
jslint http://www.jslint.com/
JS UT:
http://www.jsunit.net/
JS ST:
http://www.outofhanwell.com/ieleak/index.php?title=Main_Page Drip
http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx
http://blogs.msdn. ......

javascript验证1

function $id(s) {
    return document.getElementById(s);
}
//判断小数
function IsFloat(s) {
    if (!/^[+\-]?\d+(.\d+)?$/.test(s))
        return false;
    else
        return ......

javascript获取分辨率,网页窗口大小等值

<html>19楼空间,`(uqj3~9?!F
<body>
Ob*p#?L;DL0<scrīpt   LANGUAGE="Javascrīpt">
+t:{z]tbs0var s = "";19楼空间e kA3HoT1H
s += "网页可见区域宽:" + document.body.clientWidth;19楼空间cy2if}:H/SE@
s += "<br>网页可见区域高:"+ document.bo ......

JavaScript 简单树型

<html>
 <head>
  <script type="text/javascript">
   function tree(treethis){
    if (treethis.alt == "+"){
     treethis.alt = "-";
     document.getElementById("bench").style. ......

javascript写类方式之六

这篇开始会分析流行的js库之写类方式。各种库的写类方式虽然千奇百怪,但仍然逃离不了本质---用构造函数和原型
来组装类。
6、Prototype.js的写类方式
//prototype.js中的代码
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
//简化 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号