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月26日星期四

javascript学习笔记

如果在一个statement中break lines,那么就要让被分的上句不是一个完整的语句
像这样:上句var str = "hello world" +  下句 something + "这样才行";
因为,javascript总是在完整的语句后如果你没有“;”号就自己在换行处加上,这样就有可能让你的语义不正确。

这样定义函数var method1 = var function(paramerters list) {.....}  这样有时叫做lambda function

在对象构建时,对象的属性不一定为标识符,可以为字符串;属性的値也不一定要为字符串,可以是任意的javascript表达式
像这样:var square = { "upperLeft": { x:point.x, y:point.y },
'lowerRight': { x:(point.x + side), y:(point.y+side) }};

Associative arrays are indexed by strings
Regular arrays are indexed by nonnegative integers
javascript不支持多维数组,但你可以这样 var matrix = [[1,2,3], [4,5,6], [7,8,9]];
还可以这样定义数组 var sparseArray = [1,,,,5];

null和undefined不是一回事,但 null == undefined is true!
undefined is returned when you use either a variable that has been declared,
but never had a value assigned to it or an object property that does not exist.
When the undefined value is used in a Boolean context, it converts to false. When used in a numeric context, it converts to NaN. And when used in a string context, it converts to "undefined".

null is usually considered a special value of object typea value that represents no object. null is a unique value.
When a variable holds the value null, you know that it does not contain a valid object, array, number, string, or boolean value.
When null is used in a Boolean context, it converts to false. When used in a numeric context, it converts to 0. And when used in a string context, it converts to "null".

注意javascript中,时间数据类型Date中,月从零开始计,也就是说0月是January。

个人觉得完全没有必要去 var str = new String("Hello World");尽管如果 var str = "Hello";在 str.substring()时会生成一个临时的String对象
但因为在你做+的时候它自动生成一个临时的基本类型的string_str_transient = "Hello World"这样也会有一定的开消,虽然会自动被discard

如果你没有用var去声明一个变量,那么javascript会自动为你声明一个全局的变量,也许这不是你想要的,所以最好自己坚持在声明变量时用var

注意,javascript没有block-level的变量范围

1 + 2 // Addition. Result is 3.
"1" + "2" // Concatenation. Result is "12".
"1" + 2 // Concatenation; 2 is converted to "2". Result is "12".
11 < 3 // Numeric comparison. Result is false.
"11" < "3" // String comparison. Result is true.
"11" < 3 // Numeric comparison; "11" converted to 11. Result is false.
"one" < 3 // Numeric comparison; "one" converted to NaN. Result is false.

1 评论:

sz-iris 说...

可惜我不是编程的料啊,C语言考试刚过...