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 评论:
发表评论