Skip to main content

Timeline for Flood game implementation

Current License: CC BY-SA 3.0

11 events
when toggle format what by license comment
Oct 21, 2014 at 1:23 history edited Flambino CC BY-SA 3.0
clarification
Oct 20, 2014 at 20:37 vote accept kharandziuk
Oct 20, 2014 at 20:37 vote accept kharandziuk
Oct 20, 2014 at 20:37
Oct 20, 2014 at 20:34 comment added Flambino @kharandziuk No prob. Added a link to a (simplified) refactored version - just for fun
Oct 20, 2014 at 20:32 history edited Flambino CC BY-SA 3.0
added 75 characters in body
Oct 20, 2014 at 20:11 comment added Flambino @kharandziuk The semantics aren't the same. If you just use foo?, yes, you get a boolean. But, as I quoted from the docs in my earlier comment, the ?. (or in this case ?[]) operator is a variant of that. Something like foo?.bar should be read as "if foo? is true (i.e. foo exists), then access foo's bar property"
Oct 20, 2014 at 20:05 comment added kharandziuk Maybe, I don't understand something: grid[i]? # check that i-th element exists and returns bool and grid[i]?[j] # takes j-th element of bool How does it work?
Oct 20, 2014 at 19:51 comment added Flambino @kharandziuk And yes, it's very nice - when it makes sense. For instance, let's say you want to print a Person object with an optional lastName property, and you want to make the last name uppercase. Then you could do person.lastName?.toUpperCase(). It's just a shorthand for first checking, and then using a property. Check the docs under "The existential operator": "The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties"
Oct 20, 2014 at 19:45 comment added Flambino @kharandziuk ? "absorbs" null/undefined. If you just write @grid[-1][-2] (or some other invalid coordinates) you'll get an error, because @grid[-1] is undefined, and you can't say undefined[-2]. But the ? will protect you from that. In plain JS, it could be written as square = this.grid[i] ? this.grid[i][j] : null followed by if(!square) return
Oct 20, 2014 at 19:35 comment added kharandziuk Thanks! It's a really nice answer. But: square = @grid[i]?[j] return unless square? looks like magic for me. Is it really nice to use those magic features of a language?
Oct 20, 2014 at 19:31 history answered Flambino CC BY-SA 3.0