Which code segment should you use?

HOTSPOT
You are creating a web worker for an HTML5 application.
The following tasks must be performed from within the web worker:
Register an event listener for the web worker
Start and stop the web worker
You need to define a function that performs the required tasks.
Which code segment should you use? (To answer, select the appropriate option from the
drop-down list in the answer area.)

HOTSPOT
You are creating a web worker for an HTML5 application.
The following tasks must be performed from within the web worker:
Register an event listener for the web worker
Start and stop the web worker
You need to define a function that performs the required tasks.
Which code segment should you use? (To answer, select the appropriate option from the
drop-down list in the answer area.)

Answer:

Explanation:



Leave a Reply 5

Your email address will not be published. Required fields are marked *

sixteen − 2 =


blabla

blabla

incorrect answer:

to stop a worker you should use self.termintate() according to w3schools
http://www.w3schools.com/HTML/html5_webworkers.asp

Raaph

Raaph

terminate() vs. close()

The close() method is visible inside the worker’s scope. The terminate() method is a part of the worker object’s interface and can be called “from the outside”.

If you create a worker in your main script and want to stop it from that script you should call the terminate() on the worker object. If you want to stop the worker from the worker code (for example as a response to an external message) you should call the close() method.

So self.close(); is correct in this case.

source: http://stackoverflow.com/questions/30500883/javascript-web-worker-close-vs-terminate

Rafael

Rafael

the option
self.addEventListener(‘message’ ,function(event));

is wrong

must be

self.addEventlistener(‘message’, function (event) {

becasue the end line is
}, false);

addEventListener method definition is
addEventListerner ( eventName, function, useCapture)

http://www.w3schools.com/jsref/met_document_addeventlistener.asp

Gonçalo

Gonçalo

useCapture its optional