News for hackers. Stuff that matters.
Re:Intent to stop using 'null' in my JS code by sergeykish on Sunday November 01, 2020 @03:45AM (#24958101)
undefined would be rare

    foo
    //Uncaught ReferenceError: foo is not defined
if not property access, and it lies

    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

http://sergeykish.com/ruby-like-javascript-undefined.rb

Anyone knows how to relax arity?

There are no comments on this comment yet.