JavaScript学习笔记1--语法篇摘录
2015-04-17 17:47
309 查看
Here are the falsy values:
false
null
undefined
the empty string ''
The number 0
The number NaN
/////////////////////////////////////////////////////////////////////////////////
The break statement can optionally have a label that will cause an exit from the labeled statement, like goto....
/////////////////////////////////////////////////////////////////////////////////
The equality operator: ===
/////////////////////////////////////////////////////////////////////////////////
Most languages with C syntax have block scope. All variables defined in a block (a list of statements wrapped with curly braces) are not visible from outside of the block. But JavaScript does not have block scope even though its block syntax suggests that
it does.
/////////////////////////////////////////////////////////////////////////////////
对于nodes的onclick提示的i都指向同一个内存地址,所以运行的效果提示的都是nodes的个数。
false
null
undefined
the empty string ''
The number 0
The number NaN
/////////////////////////////////////////////////////////////////////////////////
The break statement can optionally have a label that will cause an exit from the labeled statement, like goto....
var result = false; point: { var obj = { key: 1 }; for (var key in obj) { // ... break point; } result = true; } alert(result);
/////////////////////////////////////////////////////////////////////////////////
The equality operator: ===
/////////////////////////////////////////////////////////////////////////////////
Most languages with C syntax have block scope. All variables defined in a block (a list of statements wrapped with curly braces) are not visible from outside of the block. But JavaScript does not have block scope even though its block syntax suggests that
it does.
var foo = function ( ) { var a = 3, b = 5; var bar = function ( ) { var b = 7, c = 11; // At this point, a is 3, b is 7, and c is 11 a += b + c; // At this point, a is 21, b is 7, and c is 11 }; // At this point, a is 3, b is 5, and c is not defined bar( ); // At this point, a is 21, b is 5 };
/////////////////////////////////////////////////////////////////////////////////
对于nodes的onclick提示的i都指向同一个内存地址,所以运行的效果提示的都是nodes的个数。
// BAD EXAMPLE // Make a function that assigns event handler functions to an array of nodes the wrong way. // When you click on a node, an alert box is supposed to display the ordinal of the node. // But it always displays the number of nodes instead. var add_the_handlers = function (nodes) {
var i;
for (i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (e) {
alert(i);
};
}
}; // END BAD EXAMPLE
// BETTER EXAMPLE // Make a function that assigns event handler functions to an array of nodes the right way. // When you click on a node, an alert box will display the ordinal of the node. var add_the_handlers = function (nodes) {
var i;
for (i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(e);
};
}(i);
}
};
相关文章推荐
- JavaScript学习系列1 JavaScript语法
- C语言语法上与C++的不同之处-作为笔记
- xml学习笔记1--XML语法
- Shell脚本学习笔记-语法
- PHP学习笔记:3.PHP基本语法详解---运算符
- [转载]【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)
- javascript学习笔记之二 ---DOM
- Python笔记——基本语法:标识符、数据类型、变量、运算符及表达式/编码风格
- Vue.js学习笔记: 数据绑定语法---绑定表达式
- iOS笔记--oc语法3 (#include和#import的区别、#import和@class的区别)
- Python学习笔记1(基础语法)
- C#快速入门笔记(1)——基础语法
- Delphi 2010学习笔记(3)---Use从句的语法---2011-01-18
- Objective-C基础学习笔记(一)-程序整体语法结构
- PREP 语法笔记 6
- python数据结构及部分语法笔记
- PHP基础学习笔记之基本语法
- Object-C 点语法 -- 笔记
- Java高级语法笔记-文件及目录操作
- Java自学笔记之语法小述