javascript写类方式之五
5、用 构造函数+原型 定义一个类;同一构造函数可以定义出多个类型
/**
* $define 写类工具函数之二
* @param {Object} constructor
* @param {Object} prototype
*/
function $define(constructor,prototype) {
var c = constructor || function(){};
var p = prototype || {};
return function() {
for(var atr in p)
arguments.callee.prototype[atr] = p[atr];
c.apply(this,arguments);
}
}
与第四种方式类似,仍然用构造函数,原型对象,定义两个类。
//构造函数
function Person(name) {
this.name = name;
}
//原型对象
var proto = {
getName : function(){return this.name},
setName : function(name){this.name = name;}
}
//定义两个类
var Man = $define(Person,proto);
var Woman = $define(Person,proto);
console.log(Man == Woman);//false,同一个构造函数(Person)定义不同的类
相关文档:
javascript typeof的用法
经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.
if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运 ......
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. ......
1.document.write("");
为
输出语句
2.JS
中的注释为
//
3.
传统的
HTML
文档顺序是
:document->html->(head,body)
4.
一个浏览器窗口中的
DOM
顺序是
:window->(navigator,screen,history,location,document)
5.
得到表单中元素的名称和值
:document.getElementById("
表 ......
<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 ......
<html>
<head>
<script type="text/javascript">
function tree(treethis){
if (treethis.alt == "+"){
treethis.alt = "-";
document.getElementById("bench").style. ......