开发者

JavaScript - Run the designated line of code

Hi

Suppose I have a script.js file that contain hundred line of code, could I call this file and ONLY run the 开发者_StackOverflow社区designated line of code?


You should create functions in your script file.
You can then call whichever functions you want.

You can even pass parameters!


You can do this

var script = ... text of your file ...;
var N = ... line number
eval(script.split("\n")[N]);

This will execute (evaluate) line #N in your script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜