coffeescript check if not in array
isnt is the opposite of is, which is the triple equals sign. Just negate the in: if err and user not in moderators return or, using postfix if: return if err and user not in moderators
isnt is the opposite of is, which is the triple equals sign. Just negate the in: if err and user not in moderators return or, using postfix if: return if err and user not in moderators
You can define class methods by prefixing them with @: class Box2DUtility constructor: () -> @drawWorld: (world, context) -> alert ‘World drawn!’ # And then draw your world… Box2DUtility.drawWorld() Demo: http://jsfiddle.net/ambiguous/5yPh7/ And if you want your drawWorld to act like a constructor then you can say new @ like this: class Box2DUtility constructor: (s) -> … Read more
Finally I found this easy way to do it: if (MyVariable?){ … } that will generate: if (typeof MyVariable !== “undefined” && MyVariable !== null){ … } UPDATE 04/07/2014 Demo Link
Yup: passwordNotEmpty = not not password or shorter: passwordNotEmpty = !!password
Simple — place a comma by itself in a column lower than that in which you define your objects. a = [ nameA1: valueA1 nameA2: valueA2 nameA3: valueA3 , nameB1: valueB1 nameB2: valueB2 nameB3: valueB3 ] Will become: var a; a = [ { nameA1: valueA1, nameA2: valueA2, nameA3: valueA3 }, { nameB1: valueB1, nameB2: … Read more
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
No, that’s not the rule I would use. The major use-case I’ve found for the fat-arrow in defining methods is when you want to use a method as a callback and that method references instance fields: class A constructor: (@msg) -> thin: -> alert @msg fat: => alert @msg x = new A(“yo”) x.thin() #alerts … Read more
Use a single # sign # like this One character seems pretty minimal 😉 Also: ### This block comment (useful for ©-Copyright info) also gets passed on to the browsers HTML /* like this! */ ###