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

javascript写类方式之七

7、dojo.js的写类方式
dojo最新是1.3.1了,记得07年时还是0.4。文档也渐渐多了起来,用dojo的也慢慢多了。dojo还发布了core版,压缩后只有
27kb。dojo中用dojo.declare方法来定义一个类。dojo.declare的源码就不贴在这里了。dojo.declare有三个参
数,
参数1:类名className
参数2:继承的类superclass
参数3:构造器,方法props
单纯的定义一个类实际只需传第一,三两个参数。因为这里只讨论如何定义一个类,不讨论继承。代码如下:
//定义类名
var className = "Person";
//定义构造器及方法
var proto = {
constructor : function(name){this.name=name;},
getName : function(){ return this.name;},
setName : function(name){ this.name = name;}
}
//定义类Person
dojo.declare(className,null,proto);
//创建一个对象
var p = new Person("tom");
console.log(p.getName());//tom
p.setName("jack");
console.log(p.getName());//jack
//测试instanceof及p.constructor是否正确指向了Person
console.log(p instanceof Person);//true
console.log(p.constructor === Person);//true


相关文档:

javascript typeof的用法

javascript typeof的用法
经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.
if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运 ......

javascript 验证代码整理

//the common event,If your brower is firefox,you should use this function instead of "window.event"
function getEvent() {
if(document.all)
return window.event; //get ie event
func=getEvent.caller;
while(func!=null) {
......

javascript验证2

// JScript 文件
/********************************************************/
/*判定返回值为true或false*/
/********************************************************/
//打开一个新链接
function   openwindow()
  {
    //var $j = jQuery.noConflict();
    ......

javascript速记手册


1.document.write("");


输出语句
2.JS
中的注释为
//
3.
传统的
HTML
文档顺序是
:document->html->(head,body)
4.
一个浏览器窗口中的
DOM
顺序是
:window->(navigator,screen,history,location,document)
5.
得到表单中元素的名称和值
:document.getElementById("
表 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号