|
code:
Assuming you only need to handle modern browsers, the best way to work around that is to use Function.bind: code:
|
# ? Sep 29, 2013 14:02 |
|
|
# ? May 15, 2024 23:13 |
|
this is surprisingly simple. It's based on how the function is called, rather than where it's created: o.f(); will have this being o. f(); will have this being the global object without strict mode and null in strict mode. Future versions of JS will have a lexically scoped this, and method closures.
|
# ? Sep 29, 2013 14:12 |
Thanks all, that makes sense.
|
|
# ? Sep 29, 2013 14:28 |
|
You can also explicitly set this by using function.call or function.apply Probably my most abused pattern is JavaScript code:
|
# ? Sep 29, 2013 15:44 |
|
I usually just write constructor functions for my objects with methods, and in the constructor, I cache this:code:
|
# ? Sep 29, 2013 18:05 |
|
Nitpicking:code:
|
# ? Sep 29, 2013 18:30 |
|
Looking to use .draggable to rearrange some divs on the page. I would like it to snap into place and then have the other elements rearrange themselves around it. Not really sure how to approach this. I was able to get things .draggable() pretty easily as its one line of Jquery. Not really sure where to go after that. sample. code:
DholmbladRU fucked around with this message at 02:57 on Sep 30, 2013 |
# ? Sep 29, 2013 19:11 |
|
Dolex posted:Nitpicking: I prefer the "CoffeeScript style": code:
|
# ? Sep 30, 2013 17:25 |
|
So I'm trying to use the YUI compressor (http://yui.github.io/yuicompressor/) to term down a bunch of my projects .js files. Everything is working fine except for one file, datepicker.js (DatePicker v6a MIT/GPL2 @freqdec). Basically the YUI compressor is bombing out on this linecode:
[ERROR] in datepicker.js 374:50:missing ) after argument ist [ERROR] in datepicker.js 1:0:Compilation produced 1 syntax errros Now I know that this is code:
|
# ? Oct 1, 2013 19:21 |
|
That is not jquery shorthand. That is a ternary statement, and is part of javascript. It's a short way of writing an if-else. And a retarded one at that, since the condition is false. I don't know what the inline comment is. It looks like some sort of directive for a third party code processor. code:
|
# ? Oct 1, 2013 19:48 |
|
You missed the ! symbol before the comment. And IE processes those comments. So under IE it's !!false, and other browsers it's !false. http://en.wikipedia.org/wiki/Conditional_comment#Conditional_comments_in_JScript
|
# ? Oct 1, 2013 19:51 |
|
I did miss the initial !. I've said it before, and I'll say it again: gently caress IE.
|
# ? Oct 1, 2013 19:55 |
|
It's convenient to blame IE, but code that looks so awkward should be reconsidered!
|
# ? Oct 1, 2013 20:47 |
|
Cool, thanks guys. That really helped figure out what the hell that line of code was doing.
|
# ? Oct 1, 2013 23:04 |
|
I've got an interesting little knockout nut to crack and I'm wondering the best practice for this situation. Basically, I have a whole bunch of checkboxes which are all watching a ko.computed to see if the observableArray which contains checked selections from all of them has reached a length of three. If so, they all disable, since the business rule is that up to 3 checkboxes can be selected. The problem with that is it just disables all of them, even the ones already selected, so the user can't change selections. I need to leave checked checkboxes enabled. So, I need to see if the given checkbox is checked or not, and if it isn't, to then check if the observableArray of checked box values has reached a count of 3, and if that's true, to then disable itself. So, does this mean just in-lining stuff in the data-bind? I'm not quite sure of the syntax for "am I checked?" so I'm still in the pounding google stage. EDIT: Just found $element in the documentation. Now I just need to find out how to ask "am I clicked or not." Fuck them fucked around with this message at 15:50 on Oct 3, 2013 |
# ? Oct 3, 2013 15:40 |
|
Does Knockout allow you to utilize pseudo-selectors like :checked ?
|
# ? Oct 3, 2013 16:16 |
|
The solution was simple after I stopped over-thinking it:code:
|
# ? Oct 3, 2013 18:47 |
|
X-post from the web thread, didn't see this thread until someone mentioned it. Node.js/express question, hope this is the right place. In app.js: code:
code:
code:
My only guess is that maybe index is a special case, and get's called automatically? The documentation and tutorials on all of this has been terrible:(
|
# ? Oct 3, 2013 19:53 |
|
bobua posted:Node.js/express question, hope this is the right place. If you're using the standard express layout that it provides for you when you use the command line generator, it should require('./routes'); or something like that at the top of app.js. code:
code:
code:
code:
code:
|
# ? Oct 3, 2013 21:27 |
|
Auh, from your link... If there is no package.json file present in the directory, then node will attempt to load an index.js or index.node file out of that directory. Makes sense. I don't know javascript or web stuff, jumping in blind, so everything I was googling was 'express documentation,' didn't realize this was more about node.js. Thanks.
|
# ? Oct 3, 2013 21:48 |
|
I'm essentially modern JavaScript-stupid, but I'm trying to use and abuse jQuery Knob as a sort of speedometer readout. I have a knob specified like so (line breaks added to not break tables):code:
code:
code:
(Yes I know this is crap code, it's totally a first cut bodged together kludge.) Any ideas? Seems like the jQuery Knob demo page has a fancy clock, which I can see how he did from the source with a simple clock() function, but jamming JSON values in on update is beyond my feeble JS comprehension at the moment (clearly something I need to work on -- I can no longer get by ignoring JS and web-based GUIs).
|
# ? Oct 4, 2013 16:34 |
|
So I discovered Three.js a little bit ago and I fukkin' love it despite the fact that I'm not the biggest fan of JavaScript. One of the bad things about Three.js is that the documentation is a teeny bit inconsistent. To that end I've decided to start contributing to it on Github (babbys first Github contribution on a "big" project). The main thing that's been bugging the poo poo out of me is that the constructors sometimes don't list if an argument is optional. So I've run into two (as of now) different ways that people are handling optional arguments. One is code:
code:
|
# ? Oct 5, 2013 22:39 |
|
Tres Burritos posted:So I discovered Three.js a little bit ago and I fukkin' love it despite the fact that I'm not the biggest fan of JavaScript. One of the bad things about Three.js is that the documentation is a teeny bit inconsistent. When you try to evaluate a variable in a conditional or logical operator, javascript considers the value "falsy" if it is: false, 0, "", NaN, null, or undefined All other values are considered "truthy". The short circuit evaluation means that when evaluating expressions with logical operators, if the first operand gives you the answer then you don't need to evaluate the second one. So if variable x is truthy in "x || y" then no matter what y is, we know the expression will be true, so we return x. If x is falsy then the value of the expression depends entirely on y, so return y. Similarly if the first operand in a && operation is false, then the whole expression must be false. Just remember that || and && don't necessarily return an actual boolean, they return the value of the left or right operand.
|
# ? Oct 6, 2013 00:34 |
|
peepsalot posted:Wisdom Appreciate it man.
|
# ? Oct 6, 2013 02:16 |
|
I'm using Angular to work on a proof of concept for a work side project and have some questions I need some help with. Right now I'm trying to make a generic controller that will handle any number of different data items without having to specifically create controller logic to call them out. Right now my controller basically only gets a stubbed JSON response (will be replaced by a real call if I can get this prototype working) that is then used to display the data on the page (very simple). This works fine for your standard 2 way data binding and getting all of the content on the page, but in order to utilize something additionally like the ngTable directive or the ngGrid to better display some page content, I'm looking at having to write specific code in my controller. So my question is, is there a way that I can look at my data returned from my JSON call and check to see if there are any items that are an array and have a parameter such as "use-grid": true, and then dynamically display those on the page without writing specific controller logic? Basically, check for any array that has a properties object that can then be used as the settings for my ngTable and have my controller iterate through all of the JSON to find these. For reference, here's the code that's required to use the ngTable. code:
|
# ? Oct 8, 2013 15:52 |
|
I have a programming assignment and I'm not sure where to start although I'm sure it will require JS at some point so I figured I'd post here, I need to create a webpage that displays a table like this http://imgur.com/cbgRmnW the user should then be able to upload an xml file on the page that contains programming information to fill the table up like this http://imgur.com/RQJal42 My questions: * What libraries, if any could help me create this? * How do I create a table that can be filled so dynamically, in the xml file if a programme is specified as finishing at an odd time like 5:47 how do we create a table that can be filled with cells that start/finish anywhere? * The new cells that are added need to also be clickable and bring up a small info popup over the table, how could this be implemented. I code in C++ mainly so this web stuff is a little alien to me although I obviously grasp the concepts quickly and am ready to learn. Any ideas?
|
# ? Oct 9, 2013 14:43 |
|
Try creating that layout with just some static HTML and fake data using the <table> tag. That should give you an idea about what to do, first. Then look at generating it. (You don't need JavaScript, except for the popup at the end, FYI)
|
# ? Oct 9, 2013 15:31 |
|
Fox1 posted:I have a programming assignment and I'm not sure where to start although I'm sure it will require JS at some point so I figured I'd post here, I need to create a webpage that displays a table like this jQuery and the templating library of your choice. Angular seems popular, but I haven't used it. I have used Knockout and liked it for the most part. jQuery will help you parse the XML that you could potentially read using the file system API if you don't mind not supporting about 65% of all users. If that's not acceptable, you're going to have to store the XML server-side somehow. You probably skip the whole <table> structure and use <div>s with percentage-based widths instead. Table layouts start to suck pretty quickly as soon as you want to do fancy things with them. Ask in the design and development thread about getting the layout right. There are some guys there who are crazy good at CSS. jQuery UI has a simple modal dialog widget you could use.
|
# ? Oct 9, 2013 15:40 |
|
None of the above advice is correct. Please ignore it.Munkeymon posted:jQuery and the templating library of your choice. Angular seems popular, but I haven't used it. I have used Knockout and liked it for the most part. jQuery will help you parse the XML that you could potentially read using the file system API if you don't mind not supporting about 65% of all users. If that's not acceptable, you're going to have to store the XML server-side somehow. He does not need a templating library. I'm assuming that the professor wanted him to generate HTML on the server-side from a simple XML file, but he's best to go back to the professor and asking what he wanted. Munkeymon posted:You probably skip the whole <table> structure and use <div>s with percentage-based widths instead. Table layouts start to suck pretty quickly as soon as you want to do fancy things with them. Ask in the design and development thread about getting the layout right. There are some guys there who are crazy good at CSS. What the gently caress is this? He wants to build a time table. That's *exactly* what <table> is for!
|
# ? Oct 9, 2013 15:45 |
|
Munkeymon posted:jQuery and the templating library of your choice. Angular seems popular, but I haven't used it. I have used Knockout and liked it for the most part. jQuery will help you parse the XML that you could potentially read using the file system API if you don't mind not supporting about 65% of all users. If that's not acceptable, you're going to have to store the XML server-side somehow. Table tags are for tabular data, which is exactly what you want to display. Throw these extremely overcomplicated suggestions out the window and read up on basic HTML.
|
# ? Oct 9, 2013 18:09 |
|
Suspicious Dish posted:None of the above advice is correct. Please ignore it. I guess I jumped to the conclusion that it was supposed to be a single page app quote:What the gently caress is this? He wants to build a time table. That's *exactly* what <table> is for! It looked from the images like he wanted the cells to break out of the columns, which would be more annoying to get working with a table than with divs.
|
# ? Oct 9, 2013 18:29 |
|
Munkeymon posted:It looked from the images like he wanted the cells to break out of the columns, which would be more annoying to get working with a table than with divs. code:
|
# ? Oct 9, 2013 18:32 |
|
kedo posted:
I said "break out of" not "span". I'm thinking about representing a run_time mod column_time != 0 situation. It's not uncommon in real-life TV listings, which is probably why I was convinced it'd be a requirement. E: so, yeah, if it's not meant to be applicable to the real world, use a table because that's easier. Munkeymon fucked around with this message at 18:41 on Oct 9, 2013 |
# ? Oct 9, 2013 18:37 |
|
Munkeymon posted:I said "break out of" not "span". I'm thinking about representing a run_time mod column_time != 0 situation. It's not uncommon in real-life TV listings, which is probably why I was convinced it'd be a requirement. If you really wanted you could just make 1 column represent 5 minutes or something. Have headers with colspan=6 for every half hour.
|
# ? Oct 9, 2013 18:58 |
|
peepsalot posted:Type coercion and short-circuit evaluation. Tres Burritos posted:So I discovered Three.js a little bit ago and I fukkin' love it despite the fact that I'm not the biggest fan of JavaScript. One of the bad things about Three.js is that the documentation is a teeny bit inconsistent. To expand on your two examples, the first one is done that way because autoStart could be defined with a value of true or false, or it could be undefined and you just want to default to true. If you used short circuit evaluation then autoStart would always be true. The example autoStart = autoStart || true Could have the following values autoStart = true || true // evaluates to true autoStart = false || true // evaluates to true incorrectly autoStart = undefined || true // evaluates to true In your second example, if you wanted to default this.near to -1 if it was undefined and allow 0 as an input value, then you would have to use the first way of defaulting instead.
|
# ? Oct 10, 2013 06:22 |
Hi guys, does anyone here have any advice on this question about dynamic routing in angularjs? the long and short of it is that we're trying to pass information around between nested controllers via routing, but it doesn't appear to be working because ng-view has its own $scope. http://stackoverflow.com/questions/19295904/dynamic-routing-with-dynamic-controllers-in-angularjs Any tips are appreciated.
|
|
# ? Oct 10, 2013 13:44 |
|
Speaking of angularjs, I'm just now working through the official tutorial and...am I alone in thinking this is a terrible piece of documentation? (maybe I'm just a terrible tutorial reader) I mean, they just drop new stuff in there all the time with no clear explanation. Take, for example, step-11. They make a Phone resource and use several methods on it with no explanation of where they came from. I mean, I figured it out because I'm awesome, but judging by the comments on nearly every page the tutorial, it's just a bad bit of teaching material. Any other introductory Angular reading I should use instead of (or in addition to) this piece of poo poo?
|
# ? Oct 12, 2013 16:32 |
|
Thermopyle posted:Speaking of angularjs, I'm just now working through the official tutorial and...am I alone in thinking this is a terrible piece of documentation? (maybe I'm just a terrible tutorial reader) That's a pretty widely held opinion, the best thing to do is try to google around and find blogs that cover the same stuff that you want to do, or read through the source code and figure it out that way (someone I was talking to recently said he did that).
|
# ? Oct 12, 2013 16:37 |
|
The Angular documentation is horrific. The only reason I put up with it was because I was getting paid.
|
# ? Oct 12, 2013 16:49 |
|
|
# ? May 15, 2024 23:13 |
|
peepsalot posted:If you really wanted you could just make 1 column represent 5 minutes or something. Have headers with colspan=6 for every half hour. Or just have 1 column represent 1 minute. HTML code:
Wheany fucked around with this message at 18:47 on Oct 12, 2013 |
# ? Oct 12, 2013 18:45 |