Giter VIP home page Giter VIP logo

Comments (5)

Josh-Cena avatar Josh-Cena commented on July 20, 2024 1

I have previously said similar things: #17981 but I don't know what people generally feel about changing the syntax conventions.

from content.

Josh-Cena avatar Josh-Cena commented on July 20, 2024

Hi, we never add the target for methods, because people often take them as global variables or that you must use an identifier to get them. You can check all other instance methods' syntax. Is this particularly confusing for event listeners?

from content.

bergus avatar bergus commented on July 20, 2024

Oh, I never noticed that! Glad it's consistent at least :D

I can see your point, but I'd think that omitting the target is just as confusing. Other arguments that are passed to the method call in the syntax examples are written using identifiers (e.g. readAsArrayBuffer(blob)) or literal expressions (e.g. .addEventListener("load", (event) => {})) as well, does this cause people to assume that blob is a global variable or that the event handler must be an arrow function?
I think that by omitting the target, the chances increase the people mistake the method for a global function. Which might not even throw an error if there's a method of the same name on window.
And yes, I think this syntax is particularly confusing for setter properties like onload.

If you don't want to use an identifier, how about including at least the dot

.addEventListener("load", (event) => {});

.onload = (event) => {};

or even an ellipsis?

.addEventListener("load", (event) => {});

.onload = (event) => {};

from content.

wbamberg avatar wbamberg commented on July 20, 2024

The current format of the "Syntax" box was decided on in #2202, as part of openwebdocs/project#26. If we wanted to revisit it, it would be better to open a discussion than an issue: that said I don't know if there's much appetite for reanimating this conversation now.

from content.

bergus avatar bergus commented on July 20, 2024

@wbamberg thanks for the link! From what I read in #2202 that discussion was about converting bnf syntax for optional parameters to multiline syntax examples, not about dropping the target object.
Anyhow, @Josh-Cena already did open https://github.com/orgs/mdn/discussions/148 so I'll chime in there

from content.

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.