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 typeof的用法
经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组.
if(document.mylist.length != "undefined" ) {} 这个用法有误.
正确的是 if( typeof(document.mylist.length) != "undefined" ) {}
或 if( !isNaN(document.mylist.length) ) {}
typeof的运 ......
Build your web applications quickly and easily using the industry leading web application IDE -- Aptana Studio.
Introduction:
Aptana Studio is a complete web development environment that combines powerful authoring tools for HTML, CSS, and JavaScript, along with thousands of additional plugins ......
/*
限制输入字符的位数
str是用户输入字符串,len是要限制的位数
----------------------------
*/
function isSmall(str,len){
if (str.length<len){
return(true);
&nb ......
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 ......