Professional Documents
Culture Documents
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
3
4
5
6
// in dynamic implementation
10
11
12
13
if (isFunction(object.test)) // ECMAScript
14
15
if object.respond_to?(:test) // Ruby
16
17
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