modernserf
modernserf

Reputation: 300

object/array comparison shorthand in coffeescript?

CoffeeScript has a lot of useful shorthand regarding arrays and objects with comprehensions and destructuring. is there a quick shorthand for comparing entire objects or multiple properties thereof? i.e.

activity.date() is selected.date() and activity.month() is selected.month()

would be something a little like

activity[date(), month()] is selected[date(), month()]

I haven't seen anything like that in the docs but I figured I'd ask.

Upvotes: 1

Views: 1350

Answers (2)

Stuart M
Stuart M

Reputation: 11588

I'm not aware of any such functionality in CoffeeScript itself, but the Underscore.js library includes an isEqual function for this:

var moe   = {name : 'moe', luckyNumbers : [13, 27, 34]};
var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};
moe == clone;
=> false
_.isEqual(moe, clone);
=> true

Upvotes: 4

Ven
Ven

Reputation: 19040

I'm afraid there's nothing like that, even more for function calls. You can use underscore's isEqual to achieve that.

Upvotes: 1

Related Questions