Does Chrome.webstore.install cause both callbacks? What for?

I am trying to embed a download of the Google Chrome extension using a functionchrome.webstore.install( link, success, fail) .

Here is a link from my <head>stanza page .

<link rel="chrome-webstore-item" 
     href="https://chrome.google.com/webstore/detail/oafp--redacted--ffencd" />

Here is the button.

<input type="button" class="btn btn-default" onclick="getExtension();">Go</input>

Here's the javascript that appears immediately before the closing tag </body>.

 <script type="text/javascript">

    function getExtension() {

      function extensionFailed(reason) {
        console.log("extension Install Failed:", reason);
      }

      function extensionInstalled() {
        console.log("installed");
      };

      console.log("calling install");
      chrome.webstore.install(undefined, extensionInstalled(), extensionFailed());
      console.log("install returned");

    };

  </script>

Pressing the button that calls getExtension gets me this sequence of events, immediately sent one by one.

  • "installation call" (right before the call chrome.webstore.install())
  • "set" (on successful callback)
  • "failed to complete installation, undefined" (when the callback fails)
  • ". (after returning from the call to chrome.webstore.install())

- , , inline .

...

  • .
  • - , undefined.
  • , .

- ....

+4
1

:

:

chrome.webstore.install(undefined, extensionInstalled(), extensionFailed());

, () extensionInstalled() extensionFailed(). , , var:

chrome.webstore.install(undefined, extensionInstalled, extensionFailed);


:

.. , , .

, IMO . , , 2 :

var myfunctionVar = function() {
    console.log('hello, world');
}

function myfunction() {
    console.log('hello, world');
}

(.. myfunctionVar() myfunction()).

, myfunctionVar , , myfunction , ( script , ). "", .

myfunctionVar(), . myfunction(), .

. .

( !) Javascript, , , , -. W3Schools.

+4

Source: https://habr.com/ru/post/1651106/


All Articles