JavaScript 變數使用 var 來宣告,
如果不使用 var, 則屬於 global object
a = 1; //global
function init() {
b = 2; //global
var c = 3; //local
}
function test1() {
init();
console.log(a);
console.log(b);
console.log(c);
}
test1();
output
--------------------------------------------
1
2
exception : ReferenceError: c is not defined
變數宣告後在作用範圍內都有效
function test2() {
console.log(a);
var a = 1;
console.log(a);
}
test2();
output
--------------------------------------------
undefined
1
注意...
6/20/2013
6/07/2013
Service Locator Pattern
將取得服務的方法進行封裝, 可降低程式碼間的耦合度
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public final class ServiceLocator {
private static ServiceLocator sl = new ServiceLocator();
private Context c;
private Map m;
private ServiceLocator() {
try {
c = new InitialContext();
m = Collections.synchronizedMap(new HashMap());
...
jQuery Source Code 註解版
http://robflaherty.github.io/jquery-annotated-sour...
Subscribe to:
Posts (Atom)