Git Product home page Git Product logo

Comments (3)

xeioex avatar xeioex commented on August 20, 2024

@drsm Can you, please, give me the link to the specification which requires this behavior for every function?

from njs.

drsm avatar drsm commented on August 20, 2024

@xeioex i'll try to find out. but, i think it is a "common behavior", rather than requirement. my point is that if no special care has been taken to differentiate a call without an argument specified and a call with undefined(void) argument provided, then results of both calls should be the same. otherwise there will be inconsistencies between internal and user-defined functions.

>> function id(x) { return x; }
undefined
>> id() === id(void 0)
true
>> (function wrapfail(x) { return 2..toString(x); })()
RangeError
    at Number.prototype.toString (native)
    at anonymous (:1)
    at main (native)

also, if we want to implement the "default function parameters" feature, let's consider this sample:

> function defaults(x = 10) { return x; }
undefined
> defaults() === defaults(void 0)
true

and finally, all of [V8, Firefox, JJS] engines demonstrate the same behavior.

from njs.

drsm avatar drsm commented on August 20, 2024

here it is:
https://www.ecma-international.org/ecma-262/5.1/#sec-10.5

4.d.ii If n is greater than argCount, let v be undefined otherwise let v be the value of the n’th element of args.

from njs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.