|
o.m. 94 posted:It is subtleties like this so easily encountered which makes me laugh whenever someone recommends JavaScript as a beginner's language The canonical JS example is when you declare the variable inside the loop, but it gets hoisted out and you see the same behavior. It's weird depending on what language you come from but not hard to understand.
|
# ? Dec 2, 2014 17:25 |
|
|
# ? Jun 5, 2024 09:35 |
|
o.m. 94 posted:It is subtleties like this so easily encountered which makes me laugh whenever someone recommends JavaScript as a beginner's language The only reason JavaScript could be considered that is because every computer has several JavaScript interpreters already installed.
|
# ? Dec 2, 2014 17:31 |
|
The precise same behaviour is present in Python as well, and I expect every language with in-line function declarations and implicit capture by reference.
|
# ? Dec 2, 2014 18:06 |
|
Wheany posted:The only reason JavaScript could be considered that is because every computer has several JavaScript interpreters already installed. (A pretty good reason.)
|
# ? Dec 2, 2014 18:10 |
|
Closing over the loop variable is something everyone gets burned by once. It can happen in most any language with closures. Ironically, I would say it's javascript's "beginner friendly" features that make it a not so great beginner language. Things like weak typing, automatic globals, semicolon insertion, and just the general attitude of chugging along after errors all make it difficult for a beginner to figure out what's going on, and encourage voodoo programming.
|
# ? Dec 2, 2014 19:53 |
|
Opulent Ceremony posted:I'd post the link to the canonical "JavaScript closure example" since the problem code is almost exactly what was posted but I can't find it. Just check http://stackoverflow.com/questions/tagged/javascript - there's probably one or two on there at all times.
|
# ? Dec 2, 2014 20:30 |
|
Wheany posted:
Does this accomplish the same thing or am I missing something? JavaScript code:
|
# ? Dec 3, 2014 00:11 |
|
enthe0s posted:Does this accomplish the same thing or am I missing something? Then getHandler(i) would call the function, which would display the alert and evaluate to undefined (default return value). So you end up calling $('#div'+i).click(undefined);
|
# ? Dec 3, 2014 00:26 |
|
enthe0s posted:Does this accomplish the same thing or am I missing something? Your code runs the function immediately, my code returns a function to be called later.
|
# ? Dec 3, 2014 16:26 |
|
What are people's thoughts on the current climate of altJS languages? I'm about to take a dive into learning Dart because there's a specific project that I'd like to contribute to. Will my time spent learning be a sunk cost after this particular piece of work is done? Is it conceivable that having demonstrable skill with Dart will help my employability? Searching 'Dart' on stackoverflow careers turns up a bunch of companies who have dart boards...
|
# ? Dec 3, 2014 17:19 |
|
Newf posted:What are people's thoughts on the current climate of altJS languages? Yeah, Dart is impossible to search for because you always get trucking jobs, Dallas public transit, and dart boards. But the language itself is great if you prefer a more classic object oriented and strongly typed approach.
|
# ? Dec 3, 2014 17:36 |
|
Newf posted:What are people's thoughts on the current climate of altJS languages? I built an app in Angular/Dart, it was awesome. But... the angular/dart team is off working on Angular 2 using AtScript with some hand-waving saying they will cross-compile to dart. So there is much fear in that community. My guess is companies that aren't using it already will avoid it.
|
# ? Dec 3, 2014 19:47 |
|
Newf posted:What are people's thoughts on the current climate of altJS languages? My hunch is that no altjs language is as useful as being real good at just pure JavaScript. Anything you know in addition is is just nice to know, unless you're applying for a job in a project that uses one.
|
# ? Dec 3, 2014 22:52 |
|
Newf posted:What are people's thoughts on the current climate of altJS languages? The only real advantage of altJs language is that you get a language with the sort of features that any respectable modern language should have. Atscript/Typescript seem useful in this regard in that they add some basic modularity/encapsulation/typing while still remaining syntactically and semantically similar to Javascript. It's not so much that it helps on a resume(probably a lot less than knowing whatever big relevant JS frameworks/libraries/platforms there are for the job) but that you can produce code that's more maintainable and reliable. The other alternative is a big boy language that can be compiled to Javascript like Clojure/Scala/Kotlin. But those all make Javascript interop a lot more difficult, and with the sorta exception of Clojurescript none have sizeable communities or a reasonably sure future.
|
# ? Dec 4, 2014 00:47 |
|
Thanks for the feedback folks. I'll keep concentrating on improving my js knowledge, and probably just pick up enough Dart to scrape by on my immediate needs. As it happens, I cracked open the two Dart packages that I aim to mush together last night, and didn't have any trouble getting started. This bit from the dart tutorial is shockingly on-the-nose with my previous posted problem: code:
|
# ? Dec 4, 2014 18:51 |
|
So is ES6: http://es6rocks.com/2014/08/what-you-need-to-know-about-block-scope-let/
|
# ? Dec 4, 2014 20:25 |
|
Good god that guy's Ubuntu dock is horrifying! All the altJS languages remind me of all the attempts at creating a "better Java" on the JVM. The languages were always immature, poorly supported, came with their own host of problems, etc. Adoption never really goes anywhere and in the meantime the native language keeps getting better and better and diminishes the need for the supposed "better" language.
|
# ? Dec 4, 2014 23:18 |
|
rrrrrrrrrrrt posted:Good god that guy's Ubuntu dock is horrifying! Yeah, try writing some ES6 with the Traceur compiler, its pretty nice.
|
# ? Dec 5, 2014 00:14 |
|
Maluco Marinero posted:Yeah, try writing some ES6 with the Traceur compiler, its pretty nice. I was just experimenting with integrating this into my React workflow today and you're right. It's pretty sweet.
|
# ? Dec 5, 2014 06:59 |
|
So... any opinions on Node.js being forked? quote:A group headed by some of Node’s most important contributors has "forked" the project, creating a new version it's calling io.js. It’s a version of Node “where contributions, releases, and contributorship are under an open governance model,” its Readme file states. More here: http://readwrite.com/2014/12/04/node-js-fork-io-js Best outcome, in my opinion, would be for Joyent to place Node.js in a foundation which would hopefully prevent two major but ultimately divergent branches being created over time.
|
# ? Dec 5, 2014 10:53 |
|
vanmartin posted:So... any opinions on Node.js being forked? Oh god, this is really stupid. It sounds like that power struggle between the companies the top contributors work for is still going on. Each of them want to be the "owners" of node so they can become the definite source for support and therefore make the most money. And it sounds like the current tactic to meet that end is to split node and gently caress up the community in the process. I haven't paid much attention to the current feuds going on, but this is likely all about money and talking poo poo about the other contributors. This is probably a lot like the time the CEO of one company publicly called a rival top contributor an rear end in a top hat on the company blog because the guy wasn't a native english speaker and didn't understand that "he" vs "he or she" was a big deal to some people. They just want more power and will do whatever poo poo they can to get that power.
|
# ? Dec 5, 2014 13:23 |
|
hello i'm new to the 'script how do i make a blank property that will hold a page element? eg. pre:myFunElement = getElementById('weedBong'); function Bong() { this.bongToLoad = {}; //this part i don't know load = function () { this.bongToLoad.getContext('4d'); this.bong.stroke(); } } function bongify() { var theBong = new Bong; theBong.bongToLoad = myFunElement; myBong.load(); }
|
# ? Dec 5, 2014 16:56 |
|
PleasureKevin posted:hello i'm new to the 'script JavaScript code:
JavaScript code:
Wheany fucked around with this message at 17:11 on Dec 5, 2014 |
# ? Dec 5, 2014 17:03 |
|
obstipator posted:Oh god, this is really stupid. It sounds like that power struggle between the companies the top contributors work for is still going on. Each of them want to be the "owners" of node so they can become the definite source for support and therefore make the most money. And it sounds like the current tactic to meet that end is to split node and gently caress up the community in the process. I haven't paid much attention to the current feuds going on, but this is likely all about money and talking poo poo about the other contributors. Open governance has no "owners" or leaders. Also, to honour the amazing person who pushed the fork button we will release the first version of IO.js on Fedor's birthday all hail the new king! Wheany posted:
But what about if I wanna load another bong element with that same object?? EDIT: OK thanks VV PleasureKevin fucked around with this message at 17:13 on Dec 5, 2014 |
# ? Dec 5, 2014 17:08 |
|
PleasureKevin posted:But what about if I wanna load another bong element with that same object?? theBong.bongToload = anotherElement
|
# ? Dec 5, 2014 17:12 |
|
PleasureKevin posted:wow, i'm hilarious This post brought me a lot of pleasure, Kevin.
|
# ? Dec 5, 2014 17:17 |
|
It's late and I'm trying to data unit testing of my Angular coverage--I'm following like an outdated book and some online guides and can't figure out what's going on here. This works:JavaScript code:
JavaScript code:
So my questions are--how should I be doing my unit tests since I want them to be as generic and decoupled as possible (i.e. only require my filters.js module, not my entire freaking app), and how should I be injecting dependencies into each bit of testing? Why does setting the filter as a variable in scope before each test raise the ReferenceError?
|
# ? Dec 8, 2014 03:09 |
|
Because filter is only in scope inside your beforeEach. Declare the variable outside the beforeEach.
|
# ? Dec 8, 2014 09:18 |
|
I got so locked in to treating the beforeEach as black magic I missed the obvious. Thanks!
|
# ? Dec 8, 2014 23:47 |
I'm trying to make a very simple binary search tree so I can write/play with various functions that add onto it. What I want to do (I think) is give var mrbstree the property root with a value of 8 and then give the root property the properties left and right with values of 7 and 9, respectively. This doesn't work var mrbstree = {}; mrbstree.root = 8; mrbstree.root.left = 7; mrbstree.root.right = 9; Edit: so the problem is that I was trying to assign properties to primitives, because I'm dumb. Is there any way other than this? mrbstree.root = {value: 8}; mrbstree.root.left = {value: 7}; mrbstree.root.right = {value: 9}; I haven't seen any references to having a BST as an array of arrays, but would that be possible/not cause problems down the line? Smerdyakov fucked around with this message at 20:25 on Dec 10, 2014 |
|
# ? Dec 10, 2014 20:10 |
|
Your conception of a tree node is a little wonky - pairing this with low confidence in your JS syntax is going to make things hairy for you. A (binary) tree node has a value and left and right references to other tree nodes. Have a look at this fiddle to get back on track: http://jsfiddle.net/fgy67832/.
|
# ? Dec 10, 2014 20:30 |
Newf posted:Your conception of a tree node is a little wonky - pairing this with low confidence in your JS syntax is going to make things hairy for you. A (binary) tree node has a value and left and right references to other tree nodes. Oh. Oh! That helps a lot and puts the other instructions I've got into the right context, thanks!
|
|
# ? Dec 10, 2014 20:45 |
|
I'm just starting to dive a little more deeply into objects, and have been fascinated with replacing switch statements with object literals (http://toddmotto.com/deprecating-the-switch-statement-for-object-literals/) Most of it I understand, but there's a piece of code that is throwing me code:
If I'm calling for an object property, I'd say something like getDrink['coke'] which would give me the value 'Coke'. Is the above code basically being interpreted by JavaScript as my saying getDrink['coke']? The return statement before the bracket notation is what is throwing me here.
|
# ? Dec 11, 2014 17:04 |
|
Raskolnikov2089 posted:I'm just starting to dive a little more deeply into objects, and have been fascinated with replacing switch statements with object literals Objects can have their keys queried by bracket notation: JavaScript code:
JavaScript code:
Replace the temp yourDrink var: JavaScript code:
JavaScript code:
Lumpy fucked around with this message at 17:16 on Dec 11, 2014 |
# ? Dec 11, 2014 17:09 |
|
Lumpy posted:
Thank you, that was exactly what was throwing me off. Seeing the longer version made it a lot more clear. I think I'll skip going that route until I'm more familiar with objects.
|
# ? Dec 11, 2014 18:13 |
|
So, I'm making a tablet version of a webpage, and I was running into an issue where the page is already partly zoomed in upon load, at different zoom levels depending on whether the tablet is in portrait or landscape mode. I added some javascript to the orientation-change handler to alter the initial-scale value on the viewport meta to scale the page to the correct level, and it works perfectly EXCEPT that when an iOS Safari user rotates from landscape to portrait mode the page is slightly off-center (as in the left edge of it is off the left edge of the screen) until they scroll. For the life of me I can't find any information on viewport adjustments making a page load off-center, so I don't know how to address this. Anybody have the slightest idea what I'm talking about or am I just babbling? It's been a long week. e: To clarify, post-viewport-adjustment the page is the correct size, but part of it is slightly off the screen. loquacius fucked around with this message at 21:36 on Dec 12, 2014 |
# ? Dec 12, 2014 21:33 |
|
loquacius posted:So, I'm making a tablet version of a webpage, and I was running into an issue where the page is already partly zoomed in upon load, at different zoom levels depending on whether the tablet is in portrait or landscape mode. I added some javascript to the orientation-change handler to alter the initial-scale value on the viewport meta to scale the page to the correct level, and it works perfectly EXCEPT that when an iOS Safari user rotates from landscape to portrait mode the page is slightly off-center (as in the left edge of it is off the left edge of the screen) until they scroll. For the life of me I can't find any information on viewport adjustments making a page load off-center, so I don't know how to address this. Anybody have the slightest idea what I'm talking about or am I just babbling? It's been a long week. Is this in the HEAD of your page? code:
|
# ? Dec 12, 2014 22:46 |
|
What are good/the best resources for an ActionScript developer like myself switching over to JavaScript? A lot of positions are open where I can get in as long as my code doesn't entirely suck.
|
# ? Dec 13, 2014 22:35 |
|
I think I'm having a bit of trouble getting my head around the proper way to do async callbacks in Node/Express. I've got the following awful code, that I want to basically query a third-party server, parse the HTML into JSON, and return it via the Express API (I'll eventually cache this data in Redis or something). The async nature of Node is kind of screwing me up:code:
However, if I log the results of the request call to the console, I see it later sets dropInData to the parsed HTML, after the request finishes. So, it definitely appears the code is happily skipping over the async request call and returning an empty JSON object like it should. But how should I make the server wait for the third party request to finish?
|
# ? Dec 13, 2014 23:53 |
|
|
# ? Jun 5, 2024 09:35 |
|
Dangerllama posted:I think I'm having a bit of trouble getting my head around the proper way to do async callbacks in Node/Express. I've got the following awful code, that I want to basically query a third-party server, parse the HTML into JSON, and return it via the Express API (I'll eventually cache this data in Redis or something). The async nature of Node is kind of screwing me up: Phone posting, so no code, but use a library like async: https://github.com/caolan/async There will be examples that do exactly what you are looking for.
|
# ? Dec 14, 2014 01:45 |