Posted about 1 month ago. Visible to the public. Linked content. Auto-destruct in 28 days

Updated: JavaScript: Testing the type of a value

Added a section about duck typing:

Duck typing

To check whether an object contains a property ("responds to a method" in Ruby lingo), use the in operator. It checks whether a property exists in the object or its prototype chain:

Copy
let parent = { parentKey: 1 } let child = Object.create(parent) child.childKey = 2 'childKey' in child // => true 'parentKey' in child // => true 'otherKey' in child // => false

Note that there is a difference between a property that is missing from an object, or a property being set to undefined:

Copy
let object = { foo: undefined } object.foo // => undefined object.bar // => undefined 'foo' in object // => true 'bar' in object // => false

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 1 month ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more