简体   繁体   English

该代码中函数结尾处的0表示什么?

[英]What is the 0 indicate at end of the function in this code?

What is the 0 define at the end of each function in this code? 此代码中每个函数末尾的0定义是什么? Why this code set 0s at the end of the function? 为什么此代码在函数末尾设置为0?

 canvas.addEventListener('mousedown', function(e) { model.dragging = getCircleForPosition(e.pageX, e.pageY); }, 0); canvas.addEventListener('mouseup', function() { model.dragging = undefined; }, 0); canvas.addEventListener('mousemove', function(e) { if (model.dragging) { model.dragging.x = e.pageX; model.dragging.y = e.pageY; redraw(); } }, 0); 

In addEventListener you can basically pass three arguments event, callback and the third one is optional which takes a boolean true for enabling event capturing and false for enabling event bubbling. 在addEventListener中,您基本上可以传递三个参数event,callback和第三个参数,后者是可选的,布尔值true表示启用事件捕获,false表示启用事件冒泡。 Here 0 will considered as false hence it will enable event bubbling on the events. 此处0将被视为false,因此将启用事件冒泡。

The 0 basically indicates a false value. 0基本上表示错误的值。 According to docs 根据文档

true - The event handler is executed in the capturing phase true-事件处理程序在捕获阶段执行

false- Default. false-默认值。 The event handler is executed in the bubbling phase 事件处理程序在冒泡阶段执行

The third argument of the addEventListner function can ether be the options object or a boolean value indicating the capturing mode. addEventListner函数的第三个参数可以是options对象或指示捕获模式的布尔值。

useCapture (Optional) -- A Boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. useCapture(可选)-布尔值,指示在将此类事件分派到DOM树中位于其下方的任何EventTarget之前,是否将分派给已注册的侦听器。 Events that are bubbling upward through the tree will not trigger a listener designated to use capture. 在树上冒泡的事件不会触发指定使用捕获的侦听器。 Event bubbling and capturing are two ways of propagating events which occur in an element that is nested within another element, when both elements have registered a handle for that event. 当两个元素都注册了该事件的句柄时,事件冒泡和捕获是传播事件的两种方式,这些事件发生在嵌套在另一个元素内的元素中。 The event propagation mode determines the order in which elements receive the event. 事件传播模式确定元素接收事件的顺序。 See DOM Level 3 Events and JavaScript Event order for a detailed explanation. 有关详细说明,请参见DOM 3级事件和JavaScript事件顺序。 If not specified, useCapture defaults to false. 如果未指定,则useCapture默认为false。

If your 0 value is interprets in a boolean context, it is to tell the even listener to not use the capture - which is the default. 如果您的0值是在布尔上下文中解释的,则是告诉偶数侦听器不要使用捕获-这是默认设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM