|
bobua posted:Speaking of AJAX(which I've never used)... Let's say you wanted a little message box on a page, and you wanted the server to be able to send messages to that box at any time, not just when the user clicks a button or something on the page. Would AJAX be the right avenue for that sort of thing? I went through the w3c's AJAX tutorial and it seemed close, but all of the examples were more about the page setting up a request and waiting for a response. Yes and no; Yes in that you can just set ajax requests on a timeout loop and keep polling the server every 5 seconds or so with ajax requests. No in that websockets might be a better way of doing it.
|
# ? Nov 4, 2013 23:10 |
|
|
# ? May 28, 2024 15:39 |
|
Maluco Marinero posted:Your object keys are really janky for working with angulars filters, so this may not work, but try escaping the inner key: No dice on the escaped key. The reason it's set up that way is because this is getting translated from XML to JSON so the data format is pretty rigid. I don't have enough of an understanding to know if I'm running into issues with the actual structure in regards to the array/objects and the orderBy's ability to index these and actually order them. I have read something about that potentially being an issue - in that case is there a way to change the grouping of my JSON data in regards to the array/objects and get that to work?
|
# ? Nov 4, 2013 23:16 |
|
excidium posted:No dice on the escaped key. The reason it's set up that way is because this is getting translated from XML to JSON so the data format is pretty rigid. I don't have enough of an understanding to know if I'm running into issues with the actual structure in regards to the array/objects and the orderBy's ability to index these and actually order them. I have read something about that potentially being an issue - in that case is there a way to change the grouping of my JSON data in regards to the array/objects and get that to work? They haven't really made their JSON in a Javascript Object friendly manner, but I guess beggars and choosers. OrderBy can't figure it out because it's expecting a different expression, and probably doesn't like inlining keys like that. Just use a getter function in your controller's scope: JavaScript code:
orderBy:getRiskDescriptionValue
|
# ? Nov 4, 2013 23:41 |
|
bobua posted:Speaking of AJAX(which I've never used)... Let's say you wanted a little message box on a page, and you wanted the server to be able to send messages to that box at any time, not just when the user clicks a button or something on the page. Would AJAX be the right avenue for that sort of thing? I went through the w3c's AJAX tutorial and it seemed close, but all of the examples were more about the page setting up a request and waiting for a response. Basically the browser makes a long duration ajax request that doesn't complete until the server sends back some data. When the data is sent back from the server the ajax call is completed and a new long-duration request is sent. I believe it is used by Gmail, and is often used for browser based chats. http://en.wikipedia.org/wiki/Comet_(programming)#Ajax_with_long_polling
|
# ? Nov 4, 2013 23:45 |
|
The longer version of what I was actually working on was a node.js account creation page. You clicked the submit button and the form data was posted, the backend then tried to do stuff like check if the account already existed, or create it. If it got created, I wanted to log them in and redirect them to a page, which was no problem. If there was a problem(account already existed\database error\anything I couldn't easily catch on the front end) I didn't want to reload the page, I just wanted a message to show up with the result(Account already exists, etc). I gave up and just did res.render(/page, msgresult: "Account already exists."); and included msgresult in the page template
|
# ? Nov 5, 2013 01:02 |
|
why does this generate an error: TypeError: Cannot set property 'y' of undefined ?code:
|
# ? Nov 5, 2013 03:48 |
Because you're in global scope there, and when you have "use strict" it won't let you use the window object as the global or something. If you want to treat your function as a class thing, try `var a = new foo(1);`
|
|
# ? Nov 5, 2013 03:52 |
|
A MIRACLE posted:Because you're in global scope there, and when you have "use strict" it won't let you use the window object as the global or something. If you want to treat your function as a class thing, try `var a = new foo(1);` I am not sure I understand. There is no window object here because this is in node. I am just trying to understand how object instantiation works in JavaScript and why this is undefined if I just call the function.
|
# ? Nov 5, 2013 03:57 |
|
Following code works:code:
|
# ? Nov 5, 2013 03:59 |
Well in node I'm not sure what the global object binds to. But use strict stops you from attaching variables to it. Basically scope isn't bound by function, it's at the object level.
|
|
# ? Nov 5, 2013 04:01 |
|
A MIRACLE posted:Well in node I'm not sure what the global object binds to. But use strict stops you from attaching variables to it. Basically scope isn't bound by function, it's at the object level. This article seems to be saying what you are saying: http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx
|
# ? Nov 5, 2013 04:07 |
|
Given that "constructors" in JavaScript are just regular functions, what were you expecting the value of this to be?
|
# ? Nov 5, 2013 04:40 |
|
Jabor posted:Given that "constructors" in JavaScript are just regular functions, what were you expecting the value of this to be? a new instance of currently executing function?
|
# ? Nov 5, 2013 05:11 |
|
The correct way to write that in strict mode is:code:
Read: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode#.22Securing.22_JavaScript
|
# ? Nov 5, 2013 06:16 |
|
I think you want .call, not .bind, Strong Sauce. But yes, this is passed based on syntax. To quote myself earlier in the thread: Suspicious Dish posted:JS does not have lexical closures, it's based on the syntax of how you called the object.
|
# ? Nov 5, 2013 06:22 |
|
Yeah wasn't sure if he was trying to return the function that he was trying to instantiate. Just trying to point out that _this_ in this case doesn't exist in strict mode.
|
# ? Nov 5, 2013 06:31 |
|
pr0metheus posted:a new instance of currently executing function? You want this to happen on every single function call?
|
# ? Nov 5, 2013 07:40 |
|
Jabor posted:You want this to happen on every single function call? Yea. Like a real constructor.
|
# ? Nov 5, 2013 07:46 |
|
pr0metheus posted:Yea. Like a real constructor. Constructors are just regular functions in JavaScript. Literally the only distinction is whether or not you use "new" when you call it. Do you seriously want the runtime to try to guess whether you're loving up, and completely change the meaning of perfectly valid code when it thinks you are? E: I mean, that "the user might be an incompetent buffoon so let's completely change what the code does if we think they made a mistake" idea is responsible for quite literally the worst anti-feature that JavaScript has. Jabor fucked around with this message at 07:58 on Nov 5, 2013 |
# ? Nov 5, 2013 07:54 |
|
Jabor posted:Constructors are just regular functions in JavaScript. Literally the only distinction is whether or not you use "new" when you call it. I am just trying to understand how constructors work in JavaScript. I thought that this keyword refers to a new instance of an object that is created whenever that function gets called. That is when a function gets called, a new object is automatically created and is accessible using this keyword from that function. But I suppose that is not the case. I also wanted to avoid new operator as its just a bunch of syntactic sugar. I suppose I should really use Object.create or constructor.call(new instance of whatever, args).
|
# ? Nov 5, 2013 08:46 |
|
The "create a new object and use it as the value of this" is entirely a property of the new operator - new f() is fundamentally equivalent tocode:
I guess it is syntactic sugar of sorts. JavaScript is kind of weird in that it has prototypal inheritance, but then it made a bunch of compromises (such as the new operator) to make it more appealing to people who were used to class-based systems. It's only relatively recently that things like Object.create have been added to let you do prototypal stuff properly.
|
# ? Nov 5, 2013 09:08 |
This discussion is why I'm a fan of this style of object creation in java script:JavaScript code:
|
|
# ? Nov 5, 2013 11:22 |
|
Err, doesn't this set myInstance === MyClass? (assuming it even parses)
|
# ? Nov 5, 2013 14:26 |
|
OddObserver posted:Err, doesn't this set myInstance === MyClass? Yes. And why wouldn't it parse?
|
# ? Nov 5, 2013 14:56 |
Yeah I guess it's a singleton. never mind
|
|
# ? Nov 5, 2013 17:57 |
|
I'm currently using this code (from here: http://bl.ocks.org/mbostock/1624660) to grab data from a cvs file and outputting a histogram.code:
my array is code:
If anyone has an experience with D3 and histograms, I'd appreciate any input, tips, etc.
|
# ? Nov 5, 2013 23:13 |
|
Does anyone know if it is possible to get pixel data for rendered html on a page using javascript? I know that pixel data can be grabbed out of a canvas element, but anything beyond that? I don't suppose a transparent canvas on top of the html would actually grab background pixel data or anything?
|
# ? Nov 6, 2013 02:16 |
|
peepsalot posted:Does anyone know if it is possible to get pixel data for rendered html on a page using javascript? I know that pixel data can be grabbed out of a canvas element, but anything beyond that?
|
# ? Nov 6, 2013 04:32 |
|
Google does it for their feedback tool. http://www.elliottsprehn.com/preso/fluentconf/#/ also this: http://stackoverflow.com/questions/4912092/using-html5-canvas-javascript-to-take-screenshots/6678156#6678156 rotor fucked around with this message at 04:57 on Nov 6, 2013 |
# ? Nov 6, 2013 04:52 |
|
Has anyone here used Google closure library to develop javascript web apps? Anyone have experience using closure in concert with javascript frameworks like ember or angular?
|
# ? Nov 6, 2013 09:31 |
|
Jam2 posted:Has anyone here used... It's probably best to just assume "yes" and if you have any questions, ask them.
|
# ? Nov 6, 2013 11:43 |
|
pr0metheus posted:I suppose when you just call a function in JavaScript it does not pass any object for prototype and is equivalent to: foo(1) <-> foo.call(undefined,1); In a regular function call, this is just a reference to the enclosing object. For a function outside of any object, that's the global object, for a method it's the object the method is being called in the context of. Strict mode changes this a little bit, if this would have been bound to the global object you get 'null' instead to let you know you're hosed up. All the new keyword does is the following: a) It binds the value of this inside the function to a new empty object, not to window or the object the function is defined on. b) That object is implicitly returned at the end of the function, unless you explicitly return something else.
|
# ? Nov 6, 2013 11:44 |
|
stoops posted:I'm currently using this code (from here: http://bl.ocks.org/mbostock/1624660) to grab data from a cvs file and outputting a histogram. I do not have any experience with d3, but I read their docs quick and it looks like when you parse a CSV file with d3, it creates a set of objects based off the header. So the CSV file: code:
code:
So: code:
code:
code:
Again, I have never used d3 before, so I could be lying to you, but that should work in theory.
|
# ? Nov 6, 2013 15:31 |
|
Lumpy posted:
Thanks, Lumpy. It worked and your explanation was clear, so I appreciate that. (Now, I just gotta figure out the scaling.)
|
# ? Nov 6, 2013 17:47 |
|
peepsalot posted:Does anyone know if it is possible to get pixel data for rendered html on a page using javascript? I know that pixel data can be grabbed out of a canvas element, but anything beyond that? There's this thing https://developer.mozilla.org/en-US/docs/Web/CSS/element that FF supports that might let you do it on there and maybe everywhere else some time in the 2030s.
|
# ? Nov 6, 2013 21:40 |
|
Munkeymon posted:There's this thing https://developer.mozilla.org/en-US/docs/Web/CSS/element that FF supports that might let you do it on there and maybe everywhere else some time in the 2030s. I'm going to assume this doesn't actually give you access to the pixels of the element, only allows you to use it in some other contexts that expect an image.
|
# ? Nov 7, 2013 00:39 |
The only way to do it is probably as a browser extension, like ColorZilla does.
|
|
# ? Nov 7, 2013 00:51 |
|
The Insect Court posted:In a regular function call, this is just a reference to the enclosing object. For a function outside of any object, that's the global object, for a method it's the object the method is being called in the context of. Strict mode changes this a little bit, if this would have been bound to the global object you get 'null' instead to let you know you're hosed up. Thank you for a succinct explanation! Just what I was looking for!
|
# ? Nov 7, 2013 07:13 |
|
Jabor posted:I'm going to assume this doesn't actually give you access to the pixels of the element, only allows you to use it in some other contexts that expect an image. Could be - I didn't dig too far into it beyond seeing it in MDN and thinking it'd be pretty neat to have. Certainly would solve a problem I ran into recently.
|
# ? Nov 7, 2013 17:44 |
|
|
# ? May 28, 2024 15:39 |
|
I could use a sanity check. Is there an elegant way to close an element after it's already been drawn to the DOM? Let's say I have a div like so:pre:<div class="wrapper"> </div> pre:</div><!-- .wrapper --> <div class="my-wrapper-breaking-thing"> </div> <div class="wrapper"> mmachine fucked around with this message at 22:10 on Nov 7, 2013 |
# ? Nov 7, 2013 22:06 |