为什么vBulletin在js feed中返回一个函数?

如果你加载一个vBulletin(3.6.8)js feed例如http://www.example.com/forum/external.php?type=js,你会得到这样的输出:

function thread(threadid, title, poster, threaddate, threadtime) { this.threadid = threadid; this.title = title; this.poster = poster; this.threaddate = threaddate; this.threadtime = threadtime; } var threads = new Array(15); threads[0] = new thread(370145, ...rest of threads in an array...); 

这个函数Object有什么用,如果eval()可能是不安全的,那么从javascript(Node.js)评估这个JS的安全方法是什么。

 var phantom = require('phantom'); phantom.create(function(ph) { return ph.createPage(function(page) { return page.open("http://www.example.com/forum/external.php?type=js&forumids=1&lastpost=1", function(status) { console.log("opened page? ", status); return page.get('plainText', function(content){ console.log(content); eval(content); //danger! console.log(thread); return ph.exit(); }); }); }); }); 

您可以在外部加载script标记,然后访问threads数组。

 <script src="/path/to/external.php"></script> <script> threads.forEach(function(thread) { //do something with thread, has the objects listed in thread() } </script>