o = { foo: undefined }
o.foo
//undefined
o.hasOwnProperty('foo')
//true
Array is an object, access by index is property access
a = []
a[0]
//undefined
That's unfortunate. In Ruby:
foo
#NameError (undefined local variable or method `foo' for main:Object)
defined?(foo)
#=> nil
o = Object.new
o.foo
#NoMethodError (undefined method `foo' for #<Object:0x000055f2f4e56e78>)
a = []
a[0]
#=> nil
And Ruby enforces method arity and keyword parameters:
def foo(value)
end
foo
#ArgumentError (wrong number of arguments (given 0, expected 1))
def bar(value:)
end
bar
#ArgumentError (missing keyword: :value)
Basically it throws on undefined.
I think reimplementation is a great way to uncover how things work, Ruby "fix" for property access
I think reimplementation is a great way to uncover how things work, Ruby "fix" for property access
http://sergeykish.com/ruby-like-javascript-undefined.rb
Anyone knows how to relax arity?