|
Dr Monkeysee posted:arguments is a particular quirk of JavaScript but other languages have something sorta similar (C# has params arguments, C/C++ has variadic functions, and nearly every dynamic language has *some* way of passing arbitrary arg lists to methods). The main difference between Javascript's arguments and other languages is that arguments a) contains all of the passed arguments and b) is not actually an array. Any other language I can think of that supports variable argument definitions has both an explicit way of defining access to them (*args in ruby) and the list of variable arguments is not some special "object".
|
# ¿ Aug 16, 2014 03:57 |
|
|
# ¿ Apr 29, 2024 16:37 |
|
nexus6 posted:I'm not trying to be fancy, I'm trying to get it to do its default functionality. Something appears to be blocking it, I can see that there should be a JS file being run that, for some reason, isn't. Since I'm not getting any console errors I'm at a loss to find out what is (or isn't) happening. That seems like an issue with Drupal that should be taken up in a related thread? Or maybe their support site.
|
# ¿ Aug 26, 2014 22:43 |
|
Bruegels Fuckbooks posted:You can stop an image (or anything else) download by doing something like: This is exactly what was suggested 3 posts up (and what Subjunctive was responding to).
|
# ¿ Sep 17, 2014 08:21 |
|
Wheany posted:Maybe with some fuckery like this: Yeah, something like this should work. You'll want to make sure you are handling "unloading" the old script (unhooking events, stopping timers, etc...) though.
|
# ¿ Sep 24, 2014 21:43 |
|
My Rhythmic Crotch posted:$.ajax Well, to get a modal you'd want to use the built-in confirm or one of the many modal libraries (bootstrap, foundation, jquery UI's dialog). Then use $.ajax when they confirm the save.
|
# ¿ Oct 6, 2014 20:20 |
|
Wheany posted:Don't use alert() or confirm() for anything, just use some UI kit's dialogs. Which is why I mentioned them. `confirm` works fine for quick mockups and mucking about, though.
|
# ¿ Oct 7, 2014 17:58 |
|
Raskolnikov2089 posted:I need to write this example over and over 100 times. In my mind, I couldn't figure out why JavaScript wasn't pointing to the global foo(), but I didn't fully grasp how local variables can take precedence over global ones. Scope is one of the most important things to grasp in Javascript. This StackOverflow post has a terse but good overview of variable scoping in JS.
|
# ¿ Oct 31, 2014 04:23 |
|
Tomed2000 posted:This might be a dumb question but why do JavaScript libraries use IIFEs if they simply modify the global object in the end anyway? For example this guy says to declare the library in an IIFE then says window.Q = Q. Why not just declare a function named Q which returns the new library object when called? In both cases you are creating new scopes and in both cases you are only adding one function to the global scope. What am I missing here? Two reasons why IIFE is important here:
|
# ¿ Nov 2, 2014 08:11 |
|
Opulent Ceremony posted:I'm confused, how is Library being created once in this case? It looks like whenever you call Q() the Library constructor function is run and a new object is returned. A new object is allocated, but the prototype of that object is already allocated in the IIFE. If you did the entire thing in Q() the object and the prototype would be allocated for each call.
|
# ¿ Nov 4, 2014 18:36 |
|
loquacius posted:Another question related to my previous issue: I have scroll event listeners in place that make changes to the page depending on where the user has scrolled. If I scroll around using a laptop touchpad (or tablet touchscreen), the scroll event fires and the listeners do their job as long as my fingers are still touching the pad/screen. If I "flick" my way around the page with a quick swipe, though, neither the "scroll" event nor the "touchmove" event seems to fire. Is there another event I should be listening on to deal with swipes or am I SOL? Probably SOL? I have had an awful time trying to interact with touchpads/screens and scroll/touch events.
|
# ¿ Nov 12, 2014 20:25 |
|
Storgar posted:Wow, great response! I guess its not too early to start using jQuery. If you're not worrying about older browsers you can skip jquery just fine. It does add some convenience (for example, adding event listeners to a bunch of elements matching a similar selector), but its definitely not necessary.
|
# ¿ Nov 24, 2014 04:54 |
|
Pollyanna posted:Require.js is bizarre and I just cannot wrap my head around it. I have a Yeoman-generated app that's based on a React UI, and I just cannot figure out how I'm supposed to add Backbone to the dependencies and be able to use it. I ran bower install backbone --save then grunt bower just like the Yo docs tell me to do, and it says that it "Updated RequireJS config with installed Bower components" , but Backbone is never actually loaded and the config doesn't actually change! Require.js has been such a pain in the rear end to wrangle that I'm really regretting using it for my project. Can anyone tell me how to get this frickin' thing to work? You need to add backbone: "path/to/backbone" to the paths key in the config. Also, require.js doesn't load anything until you reference it. Does app reference backbone in the dependency list? If not, it will not get loaded in your example.
|
# ¿ Nov 24, 2014 19:50 |
|
Kobayashi posted:Modern web tooling is such a loving joke. It gets me every time. I will never understand why they thought it was a good idea.
|
# ¿ Nov 25, 2014 03:22 |
|
Xenoveritas posted:Of course I have no clue why that logic also applies to the part where you're explicitly indicating where to locate a given named module. That's kind of my point. Pick one and stick with it.
|
# ¿ Nov 25, 2014 06:06 |
|
Pollyanna posted:(define([], function{}){}).call(this) Well yeah if you right it that way it will be a mess (of not working).
|
# ¿ Nov 25, 2014 18:48 |
|
Kobayashi posted:I was looking at some code the other day, and ran across a check in the constructor that I do not understand: Because constructors in Javascript are just functions you can call ClassName({}) instead of new ClassName({}), which would cause some issues. This check basically watches for the first case and forces the actually-valid second case.
|
# ¿ Nov 26, 2014 20:33 |
|
Storgar posted:What if I want to do things like filter posts by topic, rearrange them, or reload posts without refreshing after publishing a new post? I might want to do other, more complicated things and I'm just using a blog as a learning example. All of those can be done without requiring javascript to even function as a simple blog. Its great if you're using it as a bed for learning, but a blog is one of the simplest things to build with both javascript and non-javascript users in mind. Use it as a learning bed for not just all of those amazing javascript features, but how to gracefully degrade at the same time.
|
# ¿ Nov 29, 2014 07:10 |
|
Dangerllama posted:This code always returns the empty JSON via the API: [{}] Because you are returning the initial value ({}) from getDuData. To make it work asynchronously you need to do something like: code:
|
# ¿ Dec 14, 2014 02:33 |
|
Hughmoris posted:I have a simple, single webpage that has a button called "Start Over" with coding of: Add a click event listener and check for the shiftKey modifier: http://jsfiddle.net/m9zy63v9/1/
|
# ¿ Dec 29, 2014 22:53 |
|
Suspicious Dish posted:Please use the "input" event, not "click", just in case someone uses the Enter or Space keys to activate your button. Unless those activate "click" now. They didn't used to. If he wants shift-enter to accomplish the same thing then yes. To mean that seems like an odd input combo as enter usually submits a form and its not that hard to accidentally hold shift in the process.
|
# ¿ Dec 30, 2014 13:00 |
|
Also, don't use eval. You can access properties on an object using brackets: console.log(classroom.room1.students[student2].grade + 5);
|
# ¿ Jan 2, 2015 04:54 |
|
Lumpy posted:
Will that work given the response? I thought the collection initializer took an array of objects, not URLs.
|
# ¿ Feb 5, 2015 20:03 |
|
JavaScript code:
|
# ¿ Feb 18, 2015 20:28 |
|
Misogynist posted:article and meta are undefined in this scope Oh, of course.
|
# ¿ Feb 20, 2015 02:45 |
|
Ranzear posted:
Guarantees no errors (as options.hasOwnProperty can be changed). I've started going with Object.keys to remove that dumb loving call. Downside is the scope change, but in most cases it's not that bad. code:
|
# ¿ Feb 25, 2015 07:38 |
|
Subjunctive posted:At the limit, Object.prototype.hasOwnProperty can be changed as well, of course, but it's rarer and usually compatible when things like that happen. Yeah, that's true, but if you use something like jQuery you would notice very quickly if the root Object.prototype.hasOwnProperty was overridden (unless you changed it after including, I guess). Most of the time its not a problem anyway, but its good to understand why it can be an issue.
|
# ¿ Feb 25, 2015 17:06 |
|
Wheany posted:Does anything change hasOwnProperty anywhere? Maybe like, evil.js. But nobody would seriously do it. Just use Object.keys, though. It ensures you get only the actual properties of the object, not crap from the prototype chain.
|
# ¿ Feb 25, 2015 22:40 |
|
If you move the new Inner() below Inner.prototype.p it works. I don't know why, exactly, but it's a fix!
|
# ¿ Mar 24, 2015 23:46 |
|
Newf posted:Ah... OK. The function definitions get 'hoisted' and are scoped throughout the block that they're declared in (so Inner() is available where new Inner() is called), but the property placed onto the prototype is only available below its definition. Thanks. Oh wait, yeah. After looking at it again it make sense: the constructor is called before p is set on the prototype. Oops!
|
# ¿ Mar 24, 2015 23:52 |
|
EAT THE EGGS RICOLA posted:I need to implement relatively complex dynamic autocomplete for a form using a Solr instance as the data source. Is there a straightforward way to implement this (maybe I should just rely on jquery's autocomplete stuff)? I'd just use one of the autocomplete libs. Bootstrap has a relatively decent one, I haven't used jQuery's though I'm sure it works mostly fine.
|
# ¿ Apr 9, 2015 16:50 |
|
ufarn posted:Anyone know whether it's possible to transpile the JS in an HTML file from es6 to es5? You could maybe probably hack it in with something like: code:
|
# ¿ Apr 21, 2015 19:29 |
|
JS in the browser can't do TCP/IP directly, but node or one of the other server-side ones can.
|
# ¿ Apr 26, 2015 01:52 |
|
If they are just animated constantly its not scroll hijacking. That crap people do with parallax backgrounds on scroll is janky as gently caress.
|
# ¿ May 11, 2015 18:25 |
|
WrathOfBlade posted:Not particularly, but I'll still need to parse it and evaluate it at some point. Preferably without the use of eval. Is it always going to be groups of AND separated by OR conditions? So (first) || (second) || (third)...? If that's the case it could be pretty straightforward: code:
Alternatively, while this is not a good solution, if you need more complex conditions you could simply store them as strings and eval them
|
# ¿ May 13, 2015 19:24 |
|
Something like this should work with a fixed schema:JavaScript code:
|
# ¿ May 14, 2015 18:53 |
|
The only way to ensure order is using arrays, objects in Javascript are not ordered. For a 2D grid, use a 2-dimensional array where the first dimension is rows and the second is columns.
|
# ¿ May 19, 2015 16:27 |
|
Subjunctive posted:Objects and Arrays can both have numbered properties, which can be looped over with for. The only real difference between Arrays and Objects is that Arrays maintain a length property. http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf quote:4.3.3 Object So, sure, you can use numbers if you want. But the order is not guaranteed! You may experience behavior that makes it look like it is, but the spec doe not require it and browsers do behave differently.
|
# ¿ May 20, 2015 16:36 |
|
Subjunctive posted:Arrays aren't ordered either, you just access their numeric properties in order by looping from 0 to length; you can do the same with an Object. See 15.4 of the ES5 spec, or the specification of things like Array.prototype.forEach which explicitly count from 0 to length. 12.6.4 explicitly says that the enumeration order is not specified, and that holds for all objects including Arrays. Right, but if you care about order why would you use an Object with numeric keys instead of an Array (which gives you forEach that is ordered, whereas Object.keys().forEach would not be)? The only case I could see using an Object over an Array is if your starting index isn't 0 or something (since every index before N would "exist" as undefined).
|
# ¿ May 20, 2015 19:34 |
|
Subjunctive posted:But your starting index claim is not true either; if you don't set a property on an array it doesn't exist either, per keys() or in: Ah, I could've sworn it was. Thanks for the correction. Munkeymon posted:Because you're a PHP developer and that's how it works there so that's how every other language must work, right? I haven't worked with PHP in over 6 years, so no. rear end. edit: My confusion on sparse arrays came from JSON-ifying them necrotic fucked around with this message at 18:08 on May 21, 2015 |
# ¿ May 21, 2015 18:05 |
|
|
# ¿ Apr 29, 2024 16:37 |
|
MasterSlowPoke posted:Looks like deep paranoia level sanitizing. Isn't Java strongly typed? Yes. Javascript is not, though. Guess you were referring to the now-removed post above?
|
# ¿ Jun 4, 2015 18:28 |