|
Javascript has become a powerful language. With this comes responsibility
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Wisdom you speak. Wisdom you speak...
Jeremy Falcon
|
|
|
|
|
KarstenK wrote: avascript has become a powerful language.
And Hitler was a powerful dictator.
|
|
|
|
|
I am currently writing a road traffic simulator in javascript and both at work and in this project the one thing that makes javascript difficult is scope.
Basically the manner in which scope is implemented javascript makes it that much more difficult than it needs to be.
That said I have found that programming in javascritpt has made me a better developer because there are so many ways you can do things badly in javascript.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
modified 4-Dec-17 13:21pm.
|
|
|
|
|
I know what you mean. I do find the more I use JavaScript though the more I like it. It's just where the web is at, so getting can only help ya know.
Jeremy Falcon
|
|
|
|
|
Personally I find any issues that arise from scope can be resolved by the immutability of objects. I have no idea if this is good practice, but passing object references around or just having a global or high-up object with important stuff is how I like to do it.
|
|
|
|
|
I agree with you it is not such a bad language as people try to picture it.
|
|
|
|
|
Thanks man. I totally agree. It's just different is all.
Jeremy Falcon
|
|
|
|
|
And it is still safer than C or C++ - because these two have undefined behavior.
|
|
|
|
|
Yup. Don't get me wrong, C is still a favorite language of mine. Always will be, but it's harder to take down the entire OS in JavaScript.
Jeremy Falcon
|
|
|
|
|
Yeah I see just the feature of undefined behavior (in case you are familiar with this term) is a bad feature of those languages IMHO.
|
|
|
|
|
I think you missed the point that it's fashionable to rip on JS because you "should" be using TypeScript.
#hipstercode
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Probably, but can't go and be a rebel and all and start using that now can we?
Jeremy Falcon
|
|
|
|
|
Tried the code in a new HTML page using Visual Studio 2017 and Google Chrome. The first alert showed "Apple Apple" and the second "Apple undefined". "Orange" did not show up.
TOMZ_KV
|
|
|
|
|
Double check how the project is set up then. Here's a fiddle of it...
JSFiddle[^]
Jeremy Falcon
|
|
|
|
|
I tried JSFiddle and it worked. However, when I copied the exact code to a new HTML page, it behaved the same way as it was without "Orange". Here is the complete HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
<pre>
var fruit = 'Orange';
window.fruit = 'Apple';
function explainThis() {
alert(fruit + ' ' + this.fruit);
}
explainThis();
var stuff = new explainThis();
</script>
TOMZ_KV
|
|
|
|
|
Gotcha. It's because stuff ran on JSFiddle is a mock root and not the real root. When using the real root, as in your case, window is the default object, so in the real global scope the first two lines are pretty much the same since window is the default object and so the second assignment overwrites the first. In my original code, it was a fake root so to speak. I probably should've tested it first, but hey where's the fun in that.
To illustrate...
<!DOCTYPE html>
<html lang="en">
<head>
<script>
var fruitRoot = 'Banana';
window.fruitRoot = 'Pineapple';
function explainThisRoot() {
alert(fruitRoot + ' ' + this.fruitRoot);
}
explainThisRoot();
var stuffRoot = new explainThisRoot();
(function () {
var fruit = 'Orange';
window.fruit = 'Apple';
function explainThis() {
alert(fruit + ' ' + this.fruit);
}
explainThis();
var stuff = new explainThis();
})();
</script>
</head>
<body>
</body>
</html>
Jeremy Falcon
|
|
|
|
|
That explains it.
TOMZ_KV
|
|
|
|
|
What browser are you running out of curiosity?
Jeremy Falcon
|
|
|
|
|
Chrome 62.0.3202.94 and IE 11.726.15063.0
TOMZ_KV
|
|
|
|
|
And then the MORON who declares a variable like var window; which in one browser HIDES the window object, in the other it is ignored (a few years back).
And your code works in once place, and not the other! OMFG...
Otherwise, I actually LIKE javaScript as a teachable language. Just not the environment it lives!
|
|
|
|
|
Kirk 10389821 wrote: Otherwise, I actually LIKE javaScript as a teachable language. Just not the environment it lives!
I can see that. I would think that's my biggest qualm with it too, although I extend its environment to also mean the amount of people using it and everyone wanting to put their hand in the pie and make 40 million frameworks that aren't always designed well.
Jeremy Falcon
|
|
|
|
|
I never bother with bookmarks in the Chrome browser, because I organize my URL's of interest in a separate document.
But today, I wanted to bookmark the Jacquie Lawson Advent Calendar website my mother sent me. I realized I had absolutely no clue how to bookmark a page in Chrome. Had to google it. Oh, there's a "star" icon on the URL bar that I basically always ignore.
Now, how to find the bookmark. Ummm... Google again. Oh, the vertical ... and then "Bookmarks" But my bookmark isn't there. Another layer of indirection "Bookmark Manager" OK, still not there. Another layer of indirection (at this point I'm just clicking on things randomly) it's in the "Mobile bookmarks" folder.
WTF. I'm at home, on my laptop, not some mobile device. Gawd, these UI's suck trunk sometimes.
|
|
|
|
|
And why is there not a location bar drop down either?
|
|
|
|
|
there is a menu bar, on the menu bar is an item called Bookmarks. Oh wait, I'm using a good browser.
why do people use chrome?
apart from being a memory and CPU hog it's been so simplified (which makes that 'hog' thing even less rational) it needs a pack of add-ons to be remotely useful (which exacerbates the hog-ness). Perhaps the model they are using is soviet era cars? (Yes, those have a fan club too.)
In short: chrome sucks, it's not the fastest, it's far from the best.
(even ie has standard features chrome seriously needs).
Signature ready for installation. Please Reboot now.
|
|
|
|