0

I have seen the following javascript in a webpage.

s = String["fromC" + aa.nodeValue];

May I know what is the usage of String[...]?

1
  • 1
    Where did you see that? I need a link or I can't believe it. Commented Jul 10, 2014 at 4:21

2 Answers 2

2

The square-bracket notation is just another way to access object properties or methods, usually by some kind of variable as opposed to the dot notation which accesses properties by symbol or key.

Say aa.nodeValue was equal to the string "harCode". This would work like this

var s = String["fromCharCode"];

Which is equivalent to

var s = String.fromCharCode;

So s is now a pointer to the static fromCharCode method on String.

Similarly, if aa.nodeValue was equal to "odePoint", you would be referencing String.fromCodePoint

Sign up to request clarification or add additional context in comments.

Comments

1

Its just String.fromCharCode(), written in an obfuscated way, it can be like:

aa = document.createTextNode("harCode");
s = String["fromC" + aa.nodeValue];

which would finally become String["fromCharCode"] which is equivalent to String.fromCharCode

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.