return to homepage.

three ways contact with meemail: contact with me using emailmsn: contact with me using msnQQ: contact with me using QQ

欢迎自由转载,但请注明本blog链接,谢谢合作。

文章分类

成长,转载 (1) 地税 (1) 健康 (2) 趣闻 (1) 生活杂记 (11) 转载 (4) CSS (1) Design Patterns (1) DWR (3) EJB (1) Hibernate (2) javascript (2) Jsp (2) NBA (1) Oracle (2) Struts (4) Tomcat (1) Weblogic (1) XML (1)

2007年4月28日星期六

javascript学习笔记2

尽量避免使用with语句,因为它会使你的程序变慢和可读性变差

When you intentionally use the empty statement, it is a good idea to comment your code in a way that makes it clear that you are doing it on purpose.
For example: for(i=0; i < a.length; a[i++] = 0) /* Empty */ ;

typeof:The typeof operator evaluates to "number", "string", or "boolean" if its operand is a number, string, or boolean value.
It evaluates to "object" for objects, arrays, and (surprisingly) null.
It evaluates to "function" for function operands and to "undefined" if the operand is undefined.

constructor:它是任何对象的一个属性,用来init

instanceof:instanceof operator checks the value of the constructor property

如果想让一个函数去使用一个值来保存它的一些信息,完整可以不定义全局变量,用它自己的属性就OK
// Create and initialize the "static" variable.
// Function declarations are processed before code is executed, so
// we really can do this assignment before the function declaration.
uniqueInteger.counter = 0;

// Here's the function. It returns a different value each time
// it is called and uses a "static" property of itself to keep track
// of the last value it returned.
function uniqueInteger() {
// Increment and return our "static" variable
return uniqueInteger.counter++;
}

Object is the superclass of all the built-in classes,
and all classes inherit a few basic methods from Object.

如果试图去读取一个未声明的全局变量时,会throw a exception,
但如果是读取一个未声明的对象属性就只会得到undefined而已。

声明一个变量但不给它复制,并不会覆盖也存在的同名变量。

0 评论: