Jump to content

L8V2L thoughts on JavaScript...


L8V2L

Recommended Posts

I'm trying to view a page JavaScript file. I heard you can do this by copying the file name, and adding it at the end of the end of the url. For e.g: waypasscool.com, with the src file name sonicscript.js; waypasscool.com/sonicscript.js. But when I went to go get the file name, all I found was this:

<head><script src="//www.google-analytics.com/analytics.js" async=""></script><script src="js/jquery.js" type="text/javascript"></script><script src="js/all.min.js" type="text/javascript"></script></head><body><script>  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');  ga('create', 'UA-46876714-1', 'gtrace.mobi');  ga('send', 'pageview');</script></body>
Link to comment
Share on other sites

Did you test this?

var numb= ["0", 1, "2", 3, "4"];var word = {};var letter = "0";delete(x = 0);function compare(arr, str){var x = 0;for( x in arr[x]){if(x === str){return("true");}else if(x !== str){return("false");}}};compare(numb, letter);
Link to comment
Share on other sites

Your code doesn't work. You do not understand the basic concepts, as I was asking about.

true and false shouldn't be strings, they're boolean values.

 

Here are the results of your function:

compare(["apple", "banana", "carrot"], "a"); // "false"compare(["apple", "banana", "carrot"], "apple"); // "false"compare(["apple", "banana", "carrot"], "banana"); // "false"compare(["apple", "banana", "carrot"], "0"); // "true"
Link to comment
Share on other sites

Did you test this?

var numb= ["0", 1, "2", 3, "4"];var word = {};var letter = "0";delete(x = 0);function compare(arr, str){var x = 0;for( x in arr[x]){if(x === str){return("true");}else if(x !== str){return("false");}}};compare(numb, letter);

 

Your code doesn't work. You do not understand the basic concepts, as I was asking about.true and false shouldn't be strings, they're boolean values.Here are the results of your function:

compare(["apple", "banana", "carrot"], "a"); // "false"compare(["apple", "banana", "carrot"], "apple"); // "false"compare(["apple", "banana", "carrot"], "banana"); // "false"compare(["apple", "banana", "carrot"], "0"); // "true"

 

...Okay... Edited by L8V2L
Link to comment
Share on other sites

I'm trying to view a page JavaScript file. I heard you can do this by copying the file name, and adding it at the end of the end of the url. For e.g: waypasscool.com, with the src file name sonicscript.js; waypasscool.com/sonicscript.js. But when I went to go get the file name, all I found was this:

<head><script src="//www.google-analytics.com/analytics.js" async=""></script><script src="js/jquery.js" type="text/javascript"></script><script src="js/all.min.js" type="text/javascript"></script></head><body><script>  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');  ga('create', 'UA-46876714-1', 'gtrace.mobi');  ga('send', 'pageview');</script></body>
Link to comment
Share on other sites

I'm trying to view a page JavaScript file. I heard you can do this by copying the file name, and adding it at the end of the end of the url. For e.g: waypasscool.com, with the src file name sonicscript.js; waypasscool.com/sonicscript.js. But when I went to go get the file name, all I found was this:

There's not a question there.
Link to comment
Share on other sites

No you got it right, that is one way to read external javascript files. That particular file that you pulled up is valid javascript. It is just not easily readable, as the script has been minimized. People minimize their scripts when they want to improve their website's performance (specifically in bandwidth). This, however sacrifices the readability for us programmers which is why it seems cryptic to you. Again its completely valid code and its one of those scripts that is using a number of those little nuances in the language that a programmer picks up through the years. For example the entire outer function there is wrapped in parenthesis then instantly called after definition. This is a method people use when they want to write an anonymous function that no one can re-invoke and will only run once.

(window,document,'script','//www.google-analytics.com/analytics.js','ga')

These are the parameters that are passed into that function. filling up the arguments: (i,s,o,g,r) with the (a,m) only being defined and used inside this anonymous function, reason with them being in the parameter list is so that it takes less bytes to define the local variables (no need for the 'var' keyword). You can copy a minimized script, paste it into a new file, and then expand the code over multiple lines to help make it more readable. However a lot of the code can still be cryptic if you lack the context of the variables its using. . And most minimized scripts are very, very large... I mean trying to make sense of the jQuery library by reading it's minimized script would be a nightmare. By the way I highly advise against trying to do that because:1) You can easily grab a readable version2) Even when reading the readable version, libraries those sizes often utilize a concert of design patterns. So trying to understand "why" they coded something one way wouldn't make much sense if you didn't understand the underlying patterns they are following.

 

anyway, when that script finishes running, the following variables are created (I had inner function logic expanded to what is implied):

window.GoogleAnalyticsObject = 'ga';window.ga = function (){        if (window.ga.q === null){          window.ga.q = new Array();        }            window.ga.q.push(arguments);        return null;    };window.ga.q = ['create', 'UA-46876714-1', 'gtrace.mobi', 'send', 'pageview'];window.ga.l = 1400060753032; //the specific number depends EXACTLY on when the script runs

The script also creates an extra script tag with the listed url and inserts the tag right before the very first script tag already on the page.

Link to comment
Share on other sites

I believe he's looking for a different script than the Google analytics one. There's supposed to be a file "waypasscool.com/sonicscript.js" somewhere.

Link to comment
Share on other sites

No you got it right, that is one way to read external javascript files. That particular file that you pulled up is valid javascript. It is just not easily readable, as the script has been minimized. People minimize their scripts when they want to improve their website's performance (specifically in bandwidth). This, however sacrifices the readability for us programmers which is why it seems cryptic to you. Again its completely valid code and its one of those scripts that is using a number of those little nuances in the language that a programmer picks up through the years. For example the entire outer function there is wrapped in parenthesis then instantly called after definition. This is a method people use when they want to write an anonymous function that no one can re-invoke and will only run once.

But that's not all the code, they have external JavaScript file I  want to read... I read that I can do this, by taking the name of the JavaScript file, and add that to the url that the file is currently running on, it'll brag up the file....I been studying non-stop, into the night... like now, I have went to sleep, and continue until I can't stay awake no more, then when I wake back up, I start back studying, I feel like... discourage from looking at what I feel as I should know, and it hard to find good concept lesson on JavaScript, information is scatter over the net. I'm not giving up, it just hard feeling discourage to keep going... you know.   (window,document,'script','//www.google-analytics.com/analytics.js','ga')
These are the parameters that are passed into that function. filling up the arguments: (i,s,o,g,r) with the (a,m) only being defined and used inside this anonymous function, reason with them being in the parameter list is so that it takes less bytes to define the local variables (no need for the 'var' keyword). You can copy a minimized script, paste it into a new file, and then expand the code over multiple lines to help make it more readable. However a lot of the code can still be cryptic if you lack the context of the variables its using. . And most minimized scripts are very, very large... I mean trying to make sense of the jQuery library by reading it's minimized script would be a nightmare. By the way I highly advise against trying to do that because:1) You can easily grab a readable version2) Even when reading the readable version, libraries those sizes often utilize a concert of design patterns. So trying to understand "why" they coded something one way wouldn't make much sense if you didn't understand the underlying patterns they are following. anyway, when that script finishes running, the following variables are created (I had inner function logic expanded to what is implied):
window.GoogleAnalyticsObject = 'ga';window.ga = function (){        if (window.ga.q === null){          window.ga.q = new Array();        }            window.ga.q.push(arguments);        return null;    };window.ga.q = ['create', 'UA-46876714-1', 'gtrace.mobi', 'send', 'pageview'];window.ga.l = 1400060753032; //the specific number depends EXACTLY on when the script runs
The script also creates an extra script tag with the listed url and inserts the tag right before the very first script tag already on the page.

 

Link to comment
Share on other sites

I believe he's looking for a different script than the Google analytics one. There's supposed to be a file "waypasscool.com/sonicscript.js" somewhere.

YES!
Link to comment
Share on other sites

I'mma go back over these tutorial on this site... html, html5, css, css3, and js.

 

You need to write code. Write a simple webpage that does something and get it working.

Link to comment
Share on other sites

I'm trying to view a page JavaScript file. I heard you can do this by copying the file name, and adding it at the end of the end of the url. For e.g: waypasscool.com, with the src file name sonicscript.js; waypasscool.com/sonicscript.js. But when I went to go get the file name, all I found was this: [...]

 

 

www.waypasscool.com doesn't seem to exist and seems to be an available domain name.

 

www.waypastcool.com seems to redirect to iradeutchman.com/press-kits/way-past-cool/

Link to comment
Share on other sites

Well, when you right-click on the page and select "view source" you see...

<html><head><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/><script type="text/javascript" src="js/jquery.js"></script><script type="text/javascript" src="js/all.min.js"></script><link rel="stylesheet" href="css/css.css"><title>Star Defender</title></head><body style="height:1000px;" onBlur="gameOnBlur()">	<canvas id="bg" width="600px" height="600px" style="position:absolute;"></canvas>    <canvas id="gameMain" width="600px" height="600px" style="position:absolute;"></canvas>    <canvas id="flashBuffer" width="600px" height="600px" style="position:absolute;"></canvas>	<canvas id="flash" width="600px" height="600px" style="position:absolute"></canvas><script>  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');  ga('create', 'UA-46876714-1', 'gtrace.mobi');  ga('send', 'pageview');</script></body></html>

...and since the path to the page is...

http://www.gtrace.mobi/ChromeExperiments/StarDefender/

...the path to the Javascript is...

http://www.gtrace.mobi/ChromeExperiments/StarDefender/js/all.min.js
  • Like 1
Link to comment
Share on other sites

Well, when you right-click on the page and select "view source" you see...

<html><head><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/><script type="text/javascript" src="js/jquery.js"></script><script type="text/javascript" src="js/all.min.js"></script><link rel="stylesheet" href="css/css.css"><title>Star Defender</title></head><body style="height:1000px;" onBlur="gameOnBlur()">	<canvas id="bg" width="600px" height="600px" style="position:absolute;"></canvas>    <canvas id="gameMain" width="600px" height="600px" style="position:absolute;"></canvas>    <canvas id="flashBuffer" width="600px" height="600px" style="position:absolute;"></canvas>	<canvas id="flash" width="600px" height="600px" style="position:absolute"></canvas><script>  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');  ga('create', 'UA-46876714-1', 'gtrace.mobi');  ga('send', 'pageview');</script></body></html>
...and since the path to the page is...
http://www.gtrace.mobi/ChromeExperiments/StarDefender/
...the path to the Javascript is...
http://www.gtrace.mobi/ChromeExperiments/StarDefender/js/all.min.js

 

THANK YOU!!!! :)... This is a self invoking function... right?
function myFunction(){     alert("Function called to run by Javascript"); } myFunction(); // calls the function run
Can someone give me the definition again for both recursive and invoke function... I'm getting them mix up in my head. Edited by L8V2L
Link to comment
Share on other sites

... This is a self invoking function... right?

function myFunction(){     alert("Function called to run by Javascript"); } myFunction(); // calls the function run

 

No, it's just a regular function call.

 

 

 

Can someone give me the definition again for both recursive and invoke function... I'm getting them mix up in my head.

 

then why don't you go back over your own posts, where both those questions have been answered in much detail. or just look it up. or, like has been mentioned numerous times, get a book.

 

this part of what programming is about. being resourceful and looking up simple answers in references and tutorials, or prior documented conversations. being able to connect the dots and putting independent components into play with other ones.

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...