Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

javascript - Javascript String.prototype意外令牌[关闭](Javascript String.prototype unexpected token [closed])

Apologies if this has been asked before but I couldn't find this specific issue.

(抱歉,是否曾经有人问过我,但我找不到这个特定问题。)

I've been tasked with analysing a bit of highly obfuscated, and malicious, JS code.

(我的任务是分析一些高度混淆且恶意的JS代码。)

I'm trying to get it to run in a VM at the minute just to see exactly what it's up to but I'm getting a syntax error on the first line.

(我试图让它在一分钟内在VM中运行,只是为了确切地了解它在做什么,但是第一行却出现语法错误。)

function String.prototype.x(){...

From Chrome's dev console:

(在Chrome的开发者控制台中:)

Uncaught SyntaxError: Unexpected token .

The red squiggly line shows that the error is being thrown at the first dot (between String and prototype).

(红色的波浪线表示错误正在第一个点(在String和原型之间)抛出。)

To be honest, I don't know enough about JS to figure it out but I'm sure one of you lovely lot will know the answer.

(老实说,我对JS的了解还不够,但是我敢肯定你们当中很多人都会知道答案。)

Why's it thrown and what can I do to fix it?

(为什么将其抛出,我该怎么办才能解决?)

  ask by I_GNU_it_all_along translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

String is already a class (function with the inbuilt prototype methods) in JS , in order to create methods in its prototype chain you have use as below

(String已经是JS中的类(具有内置原型方法的函数),为了在其原型链中创建方法,您可以使用以下方法)

String.prototype.reverse = function(){
  return this.split('').reverse().join()
}

"hello".reverse() // olleh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...