javascript - event.initEvent vs event.initCustomEvent - Stack Overflow

I was working on a task related to Custom Events and was wondering, is there a difference between these

I was working on a task related to Custom Events and was wondering, is there a difference between these methods apart from extra argument for event data

MDN - The old-fashioned way uses event.initEvent but the polyfill on MDN - Cutom Events uses event.initCustomEvent to initialize event.

I have referred Passing additional arguments in custom Event, but we can even use event.details to set event data.

JSFiddle - Event data with initEvent

So the question is, Is there any benefit of using specific one of them?

I was working on a task related to Custom Events and was wondering, is there a difference between these methods apart from extra argument for event data

MDN - The old-fashioned way uses event.initEvent but the polyfill on MDN - Cutom Events uses event.initCustomEvent to initialize event.

I have referred Passing additional arguments in custom Event, but we can even use event.details to set event data.

JSFiddle - Event data with initEvent

So the question is, Is there any benefit of using specific one of them?

Share Improve this question edited May 23, 2017 at 12:10 CommunityBot 11 silver badge asked Mar 9, 2016 at 13:14 RajeshRajesh 25k5 gold badges50 silver badges83 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

From the DOM spec:

The initCustomEvent(type, bubbles, cancelable, detail) method must, when invoked, run these steps:

  1. If context object's dispatch flag is set, terminate these steps.
  2. Initialize the context object with type, bubbles, and cancelable.
  3. Set context object's detail attribute to detail.

The initEvent(type, bubbles, cancelable) method, when invoked, must run these steps:

  1. If context object's dispatch flag is set, terminate these steps.
  2. Initialize the context object with type, bubbles, and cancelable.

Note: As events have constructors initEvent() is superfluous. However, it has to be supported for legacy content.

So, apart from the detail argument, they are the same.

event.initEvent This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time. MDN

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745542906a4632209.html

相关推荐

  • javascript - event.initEvent vs event.initCustomEvent - Stack Overflow

    I was working on a task related to Custom Events and was wondering, is there a difference between these

    22小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信