|
messing with setting up a JSON file with some data that gets used across a bunch of sites but each site would only need the parts that are relevant to it. I figured I would just check if each object had a certain keyword and if so grab that object. So the more relevant question for this thread would be, is indexOf really the best way to do this? I assumed something that just spits out a boolean response would be available but all I dug up was this. Second question if anyone knows, is this JSON structure alright for what I'm trying to do? JSON: code:
code:
|
# ? Oct 3, 2014 00:19 |
|
|
# ? Jun 5, 2024 07:59 |
|
You could also do something like thiscode:
My Rhythmic Crotch fucked around with this message at 01:04 on Oct 3, 2014 |
# ? Oct 3, 2014 01:00 |
|
streetlamp posted:messing with setting up a JSON file with some data that gets used across a bunch of sites but each site would only need the parts that are relevant to it. I figured I would just check if each object had a certain keyword and if so grab that object. use filter: code:
Fish Ladder Theory fucked around with this message at 17:59 on Oct 4, 2014 |
# ? Oct 4, 2014 17:49 |
|
edit: wrong thread
Analytic Engine fucked around with this message at 04:30 on Oct 6, 2014 |
# ? Oct 5, 2014 22:54 |
|
Fish Ladder Theory posted:use filter: Nice, going to try this today
|
# ? Oct 6, 2014 15:59 |
I (the client) want(s) to have a pop-up jquery box to confirm the submission of a page. What's the cleanest way to execute a modal confirmation and then fire off the server side event? I haven't done much of executing server side code from javascript. This is being done on .net and c#.
|
|
# ? Oct 6, 2014 18:53 |
|
$.ajax
|
# ? Oct 6, 2014 19:35 |
|
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 |
|
necrotic posted: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. Don't use alert() or confirm() for anything, just use some UI kit's dialogs.
|
# ? Oct 6, 2014 20:23 |
|
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 |
|
What are some good books to get caught up to speed on Javascript and, eventually, Node.js? I had Javascript and JQuery by Jon Duckett and Node.js in Action by Mike Cantelon et al recommended to me and just wanted to see if there were better ones out there. Most of my experience is with C++ and Java, and I've never really played with any web languages or technologies outside of a little bit of PHP. My goal is to pickup Node.js in a month or less. Crazy?
|
# ? Oct 14, 2014 20:42 |
|
Crazy indeed. Why would you want to learn node.js at all?
|
# ? Oct 14, 2014 23:49 |
|
My Rhythmic Crotch posted:Crazy indeed. Why would you want to learn node.js at all? Another bar regular would be able to pass on my resume with a strong recommendation, if I can give him something that he can really sink his teeth into. Node.js is a big part of their tech stack.
|
# ? Oct 15, 2014 00:24 |
|
BirdOfPlay posted:What are some good books to get caught up to speed on Javascript and, eventually, Node.js? I had Javascript and JQuery by Jon Duckett and Node.js in Action by Mike Cantelon et al recommended to me and just wanted to see if there were better ones out there. Eloquent Javascript (http://eloquentjavascript.net/) is pretty good in my opinion. If you want to dig deeper into Node after that, http://nodeschool.io/ has a lot of tutorials and exercises.
|
# ? Oct 15, 2014 01:47 |
|
Some time ago I saw links to and some pages about at least one (or more) JS UI libraries/frameworks that implemented a classical kind of nodes and wires graph GUI, similar to the interfaces of Max/MSP, Reaktor, Bidule, or Blueprints in Unreal Engine 4. Does anyone know what I'm talking about, and have links? Searching with the keywords I recall hasn't found me what I'm looking for so far. Thanks in advance.
|
# ? Oct 18, 2014 22:47 |
|
You might try something like this, which depends on D3.
|
# ? Oct 18, 2014 23:23 |
|
Are you thinking of PlumbJS? I'm using it at work combined with AngularJS under the hood to make a node-based workflow system, which is a basic ripoff of UE4 Blueprint. I posed about it over in the Data Visualisation Thread the other week. It's been really robust so far, and works on IE8, apparently (not tested). The documentation is more like a brain dump than a real guide, but once you get to grips with it, it's pretty straight forward. There's a couple of half-assed implementations of AngularJs and PlumbJS together, which are handy reference:
|
# ? Oct 19, 2014 09:26 |
|
I want some very simple tooling for javascript. All I want to do is: - Adjust some variables depending on the deployment. For example, I might have API_ROOT defined differently if I am developing on my computer vs running on the production server. - Auto-minify the main application code. - Bundle all dependencies into one file. None of this is rocket science and could be done with bash or python... which I might end up doing if the tooling is too much of a PITA. What are your experiences?
|
# ? Oct 20, 2014 05:44 |
|
Use gulp, gulp-concat, gulp-uglify, and then maybe you could stick on the start your config variables as a global object? Depends on how you want to do it, but gulp's my preferred for front end building and tooling.
|
# ? Oct 20, 2014 06:41 |
|
Anyone know if chrome apps auto-update? I'm using developer dashboard, but the documentation isn't 100% clear as to whether I need to give people a link to update to the latest version or if chrome will just update the installed app itself.
|
# ? Oct 23, 2014 16:33 |
|
As far as in aware Chrome extensions do, provided they don't expand their permission scope. I imagine its the same thing. It used to be that you could provide an update URL for checking this, but now its Web Store only its handled by that automatically.
|
# ? Oct 23, 2014 17:12 |
|
Vague question with bad code written from memory incoming! I am having trouble getting my head around setting up some dependent AJAX calls, I had this working with one call using a nested callback but I now need to add a second call and doing it by creating another nested callback seems even worse. Basically, I have two drop down lists that need to be populated with values from an object returned from an AJAX call, but the options in the drop downs are themselves dependent on attributes of the object so I need to do something like: code:
I've taken a look at using promises but these all seem to rely on using a raw ajax call, but I have wrapped my calls into functions so the whole .done thing doesn't seem to work and everything just fires off in whatever order. What I have is something like this: code:
|
# ? Oct 24, 2014 19:12 |
|
ajaxPOST sounds redundant, it sounds like you could just replace that with a direct $.post(url, {data: data, success: callback}), or $.post(url, {data: data}).then(function(){}) Anyway, if you can replace them with a post call, you can use jQuery.when() to wait for multiple promises, example from http://api.jquery.com/jquery.when/#entry-examples JavaScript code:
JavaScript code:
|
# ? Oct 24, 2014 21:03 |
|
Just checking to see if I working with Javascript by best principals. I have page with a number of jQuery tooltips on it. I'm assigning the tooltips inside my onReady function: JavaScript code:
|
# ? Oct 25, 2014 02:39 |
|
MasterSlowPoke posted:Just checking to see if I working with Javascript by best principals. Having 1 case of duplicated code is generally not considered terrible. Bu I guess you could just wrap that in a function: function addTooltip() {$('.glyphicon[title]').tooltip();}, and then just call that function from both places. That way in the future if your glyphicon selector changes, you only have to change it in that function. But it's not a huge deal.
|
# ? Oct 25, 2014 09:49 |
|
Wheany posted:ajaxPOST sounds redundant, it sounds like you could just replace that with a direct $.post(url, {data: data, success: callback}), or $.post(url, {data: data}).then(function(){}) Yeah I think you might be right - I've just wrapped something that's already wrapped and shot myself in the foot at the same time. I'll give this a go tomorrow when I'm back at work!
|
# ? Oct 26, 2014 19:47 |
|
Powerful Two-Hander posted:Yeah I think you might be right - I've just wrapped something that's already wrapped and shot myself in the foot at the same time. I'll give this a go tomorrow when I'm back at work! Trip report: I am an idiot, I forgot to actually return the jqXHR object from the ajax call so it could be used outside the wrapper! Doing that then allows the $.when(dicks).done(butts) approach to work. I've kept the wrapper as is because a) I can't be bothered to refactor existing code and b) it allows me to build some defaults into it that I'd otherwise have to copy and paste everywhere, notably a forcing off of response caching by default because IE10 will cache everything by default which can lead to unusual results.
|
# ? Oct 27, 2014 21:52 |
|
code:
|
# ? Oct 30, 2014 18:03 |
|
You're declaring a variable foo in your local scope that's shadowing the global function foo(). The declaration of foo in fooTest happens before anything else, because variable declarations (but not assignment) are hoisted to the top of their scope. It looks like this:code:
code:
Fish Ladder Theory fucked around with this message at 18:15 on Oct 30, 2014 |
# ? Oct 30, 2014 18:09 |
|
Fish Ladder Theory posted:You're declaring a variable foo in your local scope that's shadowing the global function foo(). The declaration of foo in fooTest happens before anything else, because variable declarations (but not assignment) are hoisted to the top of their scope. It looks like this: That makes a lot of sense. I understand now why the console.log before the variable declaration returns undefined. What I'm still stuck on is the debugger "TypeError: undefined is not a function" I'm getting from var foo = foo() code:
To my understanding, what is happening is this: code:
Raskolnikov2089 fucked around with this message at 18:56 on Oct 30, 2014 |
# ? Oct 30, 2014 18:43 |
|
When you type var foo = foo(), you are declaring a local variable foo, which immediately shadows the function with the same name (foo), making the global foo function inaccessible from fooTest's scope (because the declaration is hoisted). Your local reference to the global function foo is lost, because your local foo now points to undefined. Because the function foo is inaccessible, you're trying to call an undefined like it was a function. It's like you're doing this var foo = undefined; foo() // typeerror-- undefined is not a function
|
# ? Oct 30, 2014 19:36 |
|
code:
|
# ? Oct 30, 2014 22:01 |
|
Exactly.
|
# ? Oct 30, 2014 22:03 |
|
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. Thank you. A lot more of this beautiful language makes sense now.
|
# ? Oct 30, 2014 22:22 |
|
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 |
|
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?
|
# ? Nov 2, 2014 05:53 |
|
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? Can you give an example of your proposed alternative? You might find it tricky to do it some other way without either making the code less straightforward or polluting the global scope with various other definitions that are really just internal to your library.
|
# ? Nov 2, 2014 08:06 |
|
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 |
|
Jabor posted:Can you give an example of your proposed alternative? You might find it tricky to do it some other way without either making the code less straightforward or polluting the global scope with various other definitions that are really just internal to your library. Basically something like this: http://pastebin.com/ryWsAZjg. Just like in the author's example, "T" is the only thing polluting the global scope (unless I'm mistaken) and the library works as expected. necrotic posted:Two reasons why IIFE is important here: Thanks, the first point is definitely something obvious that I was missing! I haven't wrapped my head around the idea of creating plugins but it makes intuitive sense. Another thing I noticed in looking at other examples is that it seems easier to integrate your library with CommonJS and AMD if you use an IIFE instead of just having a function declaration in the global scope.
|
# ? Nov 2, 2014 15:04 |
|
|
# ? Jun 5, 2024 07:59 |
|
I'd love some help with learning how to pull data from a remote JSON API into my silly little page. I want to show the manufacturer info for a given MAC address. The site that gives that info has info about their AP here: http://www.macvendorlookup.com/mac-address-api I've bashed my head against this for a while and am not making any headway. I'm at http://domain.com/myscript.htm and want my page to grab all the nifty vendor stuff via JSONP. Sometimes I get no response but the Chrome debugger shows I've received *something* back. Other times I get endless X-Site script rejection errors. Here's some code that doesn't work: code:
Thanks for any help you can give. I've read through loads of pages on how to do this and the test code to pull images from Flickr and the like all work. I just can't get my example to work properly.
|
# ? Nov 4, 2014 00:52 |