kodejuice Posted October 26, 2014 Share Posted October 26, 2014 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 More sharing options...
niche Posted October 26, 2014 Share Posted October 26, 2014 Have you completed the js tutorials? http://www.w3schools.com/js/default.asp Link to comment Share on other sites More sharing options...
kodejuice Posted October 26, 2014 Author Share Posted October 26, 2014 Have you completed the js tutorials? http://www.w3schools.com/js/default.aspyes I Have. Link to comment Share on other sites More sharing options...
niche Posted October 26, 2014 Share Posted October 26, 2014 What's your first specific question? Link to comment Share on other sites More sharing options...
kodejuice Posted October 26, 2014 Author Share Posted October 26, 2014 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 More sharing options...
niche Posted October 26, 2014 Share Posted October 26, 2014 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Logical_operators Link to comment Share on other sites More sharing options...
davej Posted October 26, 2014 Share Posted October 26, 2014 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 More sharing options...
Ingolme Posted October 26, 2014 Share Posted October 26, 2014 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 More sharing options...
justsomeguy Posted October 27, 2014 Share Posted October 27, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now