Fairmont-Multimethods
Fairmont-Multimethods is a JavaScript library providing support for multimethods in JavaScript.
Installation
npm i -S fairmont-multimethods
Usage
equal = Methodcreate description: "'Deep' equality operator" : a == b # fallback to shallow equality # when comparing objects, recursively check the values # corresponding to the union of their properties— # return false on the first inequality Methoddefine equalisObjectisObject a == b || do -> keys = Objectkeys a...Objectkeys b... for key from keys if ! equal akeybkey return false true # when comparing arrays, recursively check values # after making sure they're the same length # return false on the first inequality Methoddefine equalisArrayisArray ax == bx || do -> return false if axlength != bxlength for i in 0..axlength if !equal axibxi return false true equal "this""this" # => true, shallow equality works here equal x: 1y: 2 x: 1y: 2 # => true, deep equality equal 1..51..5# true, deep equality equal x: 1y: 21..5# false