var line = 0;
function log(str){
line++;
document.write("<p><span style='color:blue;'>"+line+"</span>\toutput:<strong><b style='color:red;'>"
+str+"</b></strong> [Time:"+new Date()+"]</p>")
}
function plainLog(){
line++;
document.write(arguments[0]);
}
function enumPropertiesInVariable(variable){
for(property in variable){
plainLog(property+" ");
}
plainLog("<br/>");
}
function A(){
}
var a = new A;
log(a instanceof A);
log(new A() instanceof A);
a = new Object;
log(a);
log(window.a);
log(window.a === a);
var b = new Object;
log(b);
log(window.b);
log(window.b == b);
b.name="xiuye";
log(window.b.name);
//逃逸/延长lifetime
with(a){
var c = 100;
}
log(a.c);
log(c);
try{
d = 99;
}
finally{
log(d);
}
log(d);
if(true){
e = 100;
}
log(e);
for(i=0;i<10;i++);
log(i);
function f(){
global_var = 11;
var local_var = 12;
}
//需要激活
f();
log(global_var);
try{
log(local_var);
}
catch(err){
log(err.message);
log(err.stack);
}
1 output:true [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
2 output:true [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
3 output:[object Object] [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
4 output:[object Object] [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
5 output:true [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
6 output:[object Object] [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
7 output:[object Object] [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
8 output:true [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
9 output:xiuye [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
10 output:undefined [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
11 output:100 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
12 output:99 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
13 output:99 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
14 output:100 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
15 output:10 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
16 output:11 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
17 output:local_var is not defined [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]
18 output:ReferenceError: local_var is not defined at https://www.tutorialspoint.com/cg/assets/481Jsd.php:75:9 [Time:Mon May 21 2018 00:02:56 GMT+0800 (中国标准时间)]