Jump to content

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


kodejuice

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>

Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...