aardvark, antelope, ape, armadillo
Clone Javascript Array
9 02 20111. var clone = originalArray.slice(0); // not deep copy
2. CLONEDOLLY = JSON.parse(JSON.stringify(DOLLY)); // not tried yet
Comments : Leave a Comment »
Categories : Javascript
Global & local variable with the same name
18 01 2011Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable.
var scope = "global scope";
function checkscope(){
var scope = "local scope";
function nested(){
var scope = "nested scope";
alert("nested : " + scope); // nested scope
}
nested();
alert("local : " + scope); // local scope
}
checkscope();
alert("globle : " + scope); // global scope
Comments : Leave a Comment »
Categories : Javascript
References themselves are passed by value
18 01 2011A function can use the reference to modify properties of the object or elements of the array. But if the function overwrites the reference with a reference to a new object or array, that modification is not visible outside the function. Readers familiar with the other meaning of this term may prefer to say that objects and arrays are passed by value, but the value that is passed is actually a reference rather than the object itself.
var a = [1,2];
function test(v) {
var b = [2,1];
v = b;
v[0] = 11;
alert("a[0] : " + a[0]); // 1
alert("b[0] : " + b[0]); // 11
}
test(a);
Comments : Leave a Comment »
Categories : Javascript
!== & !=
12 01 2011If the two operands are of the same type and have the same value, then === produces true and !== produces false. The == and != do the right thing when the operands are of the same type, but if they are of different types, they attempt to coerce the values.

Comments : Leave a Comment »
Categories : Javascript
Objects as Associative Arrays
12 01 2011What is Associative Array?
- It is Javascript Object been used like an array
- A string containing the name of the desired property is enclosed within square brackets
When to use Objects as Associative Arrays?
- If the property names of an object aren’t known in advance and you want to find out the property values of the object
How to use it?
- Use for/in loop
Comments : Leave a Comment »
Categories : Javascript
Closures
12 01 2011JavaScript functions are a combination of code to be executed and the scope in which to execute them. This combination of code and scope is known as a closure in the computer science literature. All JavaScript functions are closures. These closures are only interesting, when a nested function is exported outside the scope in which it is defined. When a nested function is used in this way, it is often explicitly called a closure.
See below for example. The loop continues until i is 5, which is the last value of i before the function addLinks exits. Then, whenever the onclick event is actually being triggered, it takes the last value of i.
function addLinks () {
for (var i=0, link; i<5; i++) {
link = document.createElement("a");
link.innerHTML = "Link " + i;
link.onclick = function () {
alert(i);
};
document.body.appendChild(link);
}
}
window.onload = addLinks;
Using closure to get expect result:
function addLinks () {
for (var i=0, link; i<5; i++) {
link = document.createElement("a");
link.innerHTML = "Link " + i;
link.onclick = function (num) {
return function () {
alert(num);
};
}(i);
document.body.appendChild(link);
}
}
window.onload = addLinks;
Comments : Leave a Comment »
Categories : Javascript
Herbs for Healthy Living – milk thistle
6 01 2011milk thistle : 奶蓟, silybum marianum
detox : 用以解毒的,用以去毒的
metabolism : 新陈代谢
psoriasis : 牛皮癣, 银屑癣
spiky : 长而尖的
conspicuous : 显著的;显而易见的
Comments : Leave a Comment »
Tags: health, herb
Categories : English