Create an ISO date object in javascript
Try using the ISO string var isodate = new Date().toISOString() See also: method definition at MDN.
Try using the ISO string var isodate = new Date().toISOString() See also: method definition at MDN.
You have to explicitly return nothing, or to leave an expression evaluating to undefined at the bottom of your function: fun = -> doSomething() return Or: fun = -> doSomething() undefined This is what the doc recommends, when using comprehensions: Be careful that you’re not accidentally returning the results of the comprehension in these cases, … Read more
I found that the mongoose ObjectId validator works to validate valid objectIds but I found a few cases where invalid ids were considered valid. (eg: any 12 characters long string) var ObjectId = require(‘mongoose’).Types.ObjectId; ObjectId.isValid(‘microsoft123’); //true ObjectId.isValid(‘timtomtamted’); //true ObjectId.isValid(‘551137c2f9e1fac808a5f572’); //true What has been working for me is casting a string to an objectId and then … Read more
I’d recommend against doing this. See my answer at Pattern for CoffeeScript modules for some of the reasons why. (“Making your CoffeeScript code incompatible with out-of-the-box Rails 3.1” is yet another reason.) Better to just use window.a = b or even @a = b instead of a = b when you’re trying to export something … Read more
It’s a way to make sure that the compiled CoffeeScript has its own scope for variable names. This has benefits in terms of efficiency and simplicity (you know you the generated JavaScript won’t stomp on variables used by other code). You can disable it with the –bare (or -b) option to the CoffeeScript compiler. The … Read more
You can use .reduce()… array.reduce(function(max, arr) { return Math.max(max, arr[0]); }, -Infinity) Here’s a version that doesn’t use Math.max… array.reduce(function(max, arr) { return max >= arr[0] ? max : arr[0]; }, -Infinity); …and a jsPerf test.
phantomjs-node isn’t an official supported npm package for phantomjs. Instead, it implements a “nauseously clever bridge” between node and phantom by creating a web server that uses websockets to serve as an IPC channel between node and phantom. I’m not making this up: So we communicate with PhantomJS by spinning up an instance of ExpressJS, … Read more
NOTE: This question had two parts, but because the title was “Environment detection: node.js or browser” – I will get to this part first, because I guess many people are coming here to look for an answer to that. A separate question might be in order. In JavaScript variables can be redefined by the inner … Read more
You would never use the .valid() method within the .validate() method. Refer to the source code of onkeyup and onfocusout to see how it’s done. Use this.element(element) instead of $(element).valid() To over-ride the default functionality (“lazy validation”) of onkeyup and onfocusout and use “eager” validation instead… $(‘#myform’).validate({ onkeyup: function(element) { this.element(element); // <- “eager validation” … Read more
I think the problem lies with using single line comments //. Single-line comments enclosed in /* .. */ seem to work fine. Here’s an equivalent example with something other than a comment. $(‘element’).hover( -> console.log(“first”) -> console.log(“second”) ) Or with comments using /* .. */. $(‘element’).hover( -> /* first */ -> /* second */ ) … Read more