What is percent (%) in JavaScript?

人盡茶涼 提交于 2019-12-09 16:09:51

问题


I saw % in many codes. Can you explain to me its purpose or what it does?

P.S: The % is ignored from Google searches, so I couldn't find it on Google.

Edit: I know the operand in math 13 % 10 = 3 but what I saw is like return %foo.


回答1:


Based on the link you provided in the comments, the % character appears to be used in some of the V8 JavaScript engine source code to indicate a method of the C++ runtime that will be executed while parsing the JavaScript source.

For example, the line in string.js:

return %StringBuilderConcat(parts, len + 1, "");

When encountered by the parser, the StringBuilderConcat method will be executed. You can find a list of the runtime methods available to the V8 JavaScript files in runtime.h (note, I have no experience with C++, so for all I know this has nothing to do with the StringBuilderConcat method referenced in string.js, but I think it's the same thing):

#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
  /* Property access */ \
  F(GetProperty, 2, 1) \
  F(KeyedGetProperty, 2, 1) \
  /* ... */
  F(StringBuilderConcat, 3, 1) \
  /* ... */

As has already been stated, return %foo would throw a SyntaxError in JavaScript.



来源:https://stackoverflow.com/questions/11202824/what-is-percent-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!