Pattern matching for JavaScript objects