javascript - return evaluated javascript function to terminal
问题描述
I'm trying to return a function that has been evaluated to the terminal. I tried using window.onload()
, console.log();
alert();
but the URL isn't evaluated and sent to the terminal.
I run the code below using the command phantomjs test.js
var webPage = require('webpage');
var page = webPage.create();
function testlink() {
return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"]);
}
window.onload = testlink;
console.log(testlink);
alert(testlink);
Instead of getting (this is what I want)
https://ibm.com
I get
function testlink() {
return(["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"]);
}
Ps: I'm using Ubuntu 18.04 and phantomjs 2.1.1
解决方案
尝试做console.log(testlink())
而不是console.log(testlink)
如果我们想加入该数组中的所有字符,只需返回:
["h","t","t","p","s",":","\/","\/","i","b","m",".","c","o","m"].join("")
或者,如果您不想更改功能,请执行console.log(testlink().join(""))
推荐阅读
- github - 尝试将 Intellij 与 GitHub 一起使用
- python - 如何通过互联网(不是本地)使用 Python 3 套接字客户端/服务器设置?
- bash - 打开网页,查找内容并在找到后通知
- sql-server-ce - SQL Server Compact 4.0 在带有 ReadCommitted 事务的 __SysObjects 索引上死锁
- curl - cURL 配置文件 (-k / --config) JSON 换行符
- python - 如何在 Fabric 2 中使用 Connection?
- android - 我如何在颤振应用程序中下载/显示文件(pdf/ppt/docx)?
- c# - Subscribe/Listen to "side events" of the stream with System.Reactive
- php - 如何将电报机器人连接到 vps(Windows 服务器)?
- c# - out 关键字:C# 到 python 的翻译