Code Monkey home page Code Monkey logo

Comments (2)

jamesreggio avatar jamesreggio commented on May 5, 2024

πŸ‘ I agree with this convention for the reasons above, plus:

  • jQuery only allows you to pass one data argument to trigger (other systems lack this limitation)
  • it is more straightforward to re-raise an event when you only have one data argument, versus having to slice or apply arguments in order to coordinate with a multi-argument calling convention

On that subject, I believe you have a bug in your example code. The callbacks passed to jQuery.fn.on will receive a jQuery.Event instance as the first argument, followed by the data passed to trigger.

I do have the following hesitations, which I hope somebody else will second or assuage:

  • Backbone.Events bucks this convention; when subscribing to the all event, the first argument will be the event name followed by the remaining trigger payload
  • Furthermore, a significant number of Backbone.Events will pass an instance to the object that triggered the event as the first (and often only) argument

from javascript.

iamnirav avatar iamnirav commented on May 5, 2024

@jamesreggio Ah, good catch. Updated my examples. However, I'm not sure how your hesitations applyβ€”it seems like whenever you're passing a data payload with an event, you can pass an object instead of a value, regardless of the system involved.

from javascript.

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.