JavaScript OOP 4

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 (中国标准时间)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值