Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript - How does Disqus handle its "disqus_config" function which contains undefined property?

Here is a part of the Disqus's "universal code":

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

What I don't undestand is how Disqus handle this function, because page is undefined, so we cannot access to identifier or url. I have tested several examples:

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

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

like image 890
Gugelhupf Avatar asked Dec 25 '15 15:12

Gugelhupf


1 Answers

As far as I see, in the embed.js code it's something like this:

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

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

like image 170
Ciprian Mocanu Avatar answered Nov 18 '22 09:11

Ciprian Mocanu