You are on page 1of 2

http://dmitrysoshnikov.

com/ecmascript/javascript-the-core/#closures
Coming back to dynamics, weak typing and mutations of objects, in contrast with the static class
based model, passage of the test for ability to do some actions here can be related not with what
type (class) the object has, but whether it is able to respond the message (whether it is capable
to do that will be required after passing the test).
Example:

1
2

// in static class based model


if (object instanceof SomeClass) {

3
4

// some actions are allowed


}

5
6

// in dynamic implementation

// it is not essential what the type of an object

// at the moment, because of mutations, type and

// characteristics can be transformed

10

// repeatedly, but essential, whether the object

11

// can respond the "test" message

12
13

if (isFunction(object.test)) // ECMAScript

14
15

if object.respond_to?(:test) // Ruby

16
17

if hasattr(object, 'test'): // Python

On jargon, its called as duck typing. That is, objects can be identified by set of their
characteristics which are present at the moment of check, instead of objects position in
hierarchy or their belonging to any concrete type.

http://dmitrysoshnikov.com/ecmascript/javascript-the-core/#closures

You might also like