先来看个栗子:
function buildUrl() {
var qs = "?debug=true";
with(location){
var url = href + qs;
console.log(location) ;
}
return url;
}
var result = buildUrl();
alert(result);
with 语句接收的是location对象,因此其变量对象中就包含了location对象的所有属性和方法。