怎样干掉javaScript系统对象(本地对象)?

ECMA-262 把本地对象(native object)定义为“独立于宿主环境的 ECMAScript 实现提供的对象”。
“本地对象”包含哪些内容:

Object、Function、Array、String、Boolean、Number、Date、RegExp、Error、EvalError、RangeError、ReferenceError、SyntaxError、TypeError、URIError。

这些由系统提供给我们的对象,能否被干掉呢?

不要让条条框框限制了你的想象力!

雷军说,生死看淡,不服就干!

《怎样干掉javaScript系统对象(本地对象)?》 生死看淡,不服就干!

今天就带你干掉javaScript系统对象!!!

干掉String的方法:

String = null;
var a = new String('abc');
//Uncaught TypeError: String is not a constructor

通过new一个String你会发现,String确实被干掉了!String is not a constructor.

干掉Number的方法:

Number = null;
var a = new Number(123);
//Number is not a constructor

干掉Array的方法:

Array = null;
var a = new Array([1,3,4]);
//Array is not a constructor

alert能被干掉吗?

alert = null;
alert("hello world");
//alert is not a function

alert没了!

干掉setTimeout的方法:

setTimeout = null;
setTimeout(function(){
    console.log("hello world");
},1000);//setTimeout is not a function

掌握了这些方法,在javaScript里你想杀谁就杀谁!

除了这些,在javaScript里,你想让谁变成谁,就可以让它变成谁!

alert可以当console来用吗?

alert = console;
alert.log('hello world');//hello world

不要让条条框框限制了你的想象力!

window能被干掉吗?

window = null;
console.log(window);

运行上述代码你就能看到,window根本不受影响。

    原文作者:果然
    原文地址: https://www.jianshu.com/p/c8c7d52a3fc8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞