开发者

JavaScript - Run the designated line of code

开发者 https://www.devze.com 2023-03-06 07:13 出处:网络
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

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

精彩评论

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