LoginSignup
5
2

More than 5 years have passed since last update.

【超危険な】JavaScriptの組み込みオブジェクトのプロトタイプを書き換える【小ネタ】

Posted at
dangerous.js
const str="hello dengerous world";
console.log(str.slice(6, 15));

String.prototype.slice=function(){ return "hello world"; }

console.log(str.slice(6, 15));

実行結果

dengerous
hello world

JavaScriptの仕様から言って当然の結果
今回はString.prototype.sliceを使ったがなんでもできるはず
これができるということは好き放題されるということ信頼できないJSは実行しない。信頼できないライブラリは使わないが重要
あと気軽にprototypeを触るのも危険

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2