这是 Disqus 的“通用代码”的一部分:
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
};
我不明白的是Disqus是如何处理这个函数的,因为page
是undefined
,所以我们不能访问identifier
或者网址
。
我测试了几个例子:
disqus_config();
console.log(disqus_config.page);
var a = new disqus_config();
但是我还是不明白Disqus是怎么处理这个undefined
元素的。
最佳答案
据我所知,在 embed.js
代码中是这样的:
var _config = window.disqus_config;
window.disqus_config = function () {
if (_config) _config.call(this);
// Other stuff here....
};
因此,在替换它之前,disqus 会检查它是否存在,然后在自己的范围内运行它。
关于JavaScript - Disqus 如何处理其包含未定义属性的 "disqus_config"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34463988/