PrepAway - Latest Free Exam Questions & Answers

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.)

A.

Explanation:

6 Comments on “Which code segment should you use?

  1. JNash says:

    The most probably correct answer is invalid.

    The code with:
    <<
    <<self.addEventListener('message',function(event));
    <<
    cause error. The body of callback method is missing. Correct answer should be rather:

    <<
    << self.addEventListener('message',function(event){
    <<

    Pay attention on the end of line;




    0



    0
  2. Hello says:

    Re stop: There are two ways to stop a worker: by calling worker.terminate() from the main page or by calling self.close() inside of the worker itself. As it has been performed from within a web worker it should be self.close() in this case.




    1



    0

Leave a Reply