Jump to content
Sign in to follow this  
kodejuice

Please i need help, Read a javascript code line by line

Recommended Posts

I have this html/javascript +jquery code, which is meant to compile my code, but i dont know how to read the javascript as a code.//the code<!DOCTYPE html><html><head><script src="jquery.js"></script><script async>window["logerrors"] = function(){var script = $("script#val").text().replace(/[n]/ig,"};");var reps = script.replace(/};/ig,"~");var eachLine = reps.split("~");var errors ="";var err = [];for($i=0;$i<eachLine.length;$i++){try{new Function(eachLine[$i])();err.push("no");continue;} catch(e){errors += "Scope Number: "+ Number($i+1) +"<br>"+e + "<br><span style='color:red;white-space: pre'>"+eachLine[$i]+"</span><hr>";err.push("yes");continue;}}if(err.indexOf("yes") > -1){$("body").html(errors);} else{return true;}}</script></head><body onLoad="logerrors()"><script id="val">var i = jQuery;while(!i){var i = jQuery;}phrompt(i.fn.jquery);ro(q);//the while loop is an example, the code reads it as "while(){"</script></body></html>

Share this post


Link to post
Share on other sites

What's your first specific question?

Share this post


Link to post
Share on other sites

What's your first specific question?

The above code is meant to compile my code in a script tag with an id of "#val", if i read the code by line, it wont work out, cause it also read "while(!i){" as a code on its own, my question is - How do i read that particular block of code while(!i){var i = jQuery;}read this as whole and not by line

Share this post


Link to post
Share on other sites

I have this html/javascript +jquery code, which is meant to compile my code, but i dont know how to read the javascript as a code.

 

Maybe you should explain what this is supposed to accomplish.

Share this post


Link to post
Share on other sites

The above code is meant to compile my code in a script tag with an id of "#val", if i read the code by line, it wont work out, cause it also read "while(!i){" as a code on its own, my question is - How do i read that particular block of codewhile(!i){var i = jQuery;}read this as whole and not by line

While( !i ) is going to continue running the code until i has a value which isn't false, 0 or an empty string.

 

What they're actually doing is halting the program until jQuery has loaded. This is probably not a good idea: If jQuery takes long to load the browser will freeze.

Share this post


Link to post
Share on other sites

Are you trying to write a Javascript algorithm to parse Javascript code? If so, let me tell you that it takes more than a couple regular expressions and splits to figure out the structure of code. JSLint contains a parser for Javascript written in Javascript, for the version I'm linking to (2014-07-08) you can find the actual parser starting on line 2450.https://github.com/douglascrockford/JSLint/blob/master/jslint.js

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...