Javascript How does Disqus handle its disqus_config function, which contains an undefined property?

Here is part of the universal Disqus code:

var disqus_config = function () { this.page.url = PAGE_URL; // Replace PAGE_URL with your page canonical URL variable this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page unique identifier variable }; 

What I don’t understand is how Disqus handles this function because page is undefined , so we cannot access the identifier or url . I checked a few examples:

 disqus_config(); console.log(disqus_config.page); var a = new disqus_config(); 

But I still don't understand how Disqus handles this undefined element.

+5
source share
1 answer

As far as I can see, in embed.js code embed.js is something like this:

 var _config = window.disqus_config; window.disqus_config = function () { if (_config) _config.call(this); // Other stuff here.... }; 

So, before replacing, disqus checks to see if it exists, then runs it within its scope.

+1
source

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


All Articles