E
E
Eugene2019-02-06 11:50:26
Node.js
Eugene, 2019-02-06 11:50:26

How is the module for working with the Vkontakte API arranged?

I came across an interesting module for working with the Vkontakte API - VK-Promise , and I just can’t figure out its structure.
The module file contains the export of the VK function, which wraps the vk(method, params) functions - for sending requests to the API, vk.on(_event, data, add_to_event) - for creating event handlers and the vk.longpoll object with the keys start, stop and etc.
The module is connected like all the others

const VK = require("VK-Promise");
const vk = new VK("access_token");

In the file to which the module is connected, all function calls occur through vk(), vk.on(), vk.longpooll.start().
What principle is used? Unless, in order to refer to a function inside a function, it is not necessary to first write the name of the external function, and only then the internal one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-02-06
@you_are_enot

function VK(access_token, options) {
  function vk() {
    ...
  }

  vk.on = ... 
  vk.longpoll = ...

  return vk;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question