首页 \ 问答 \ 将带有函数的Javascript对象转换为字符串(Converting a Javascript Object with Functions into a String)

将带有函数的Javascript对象转换为字符串(Converting a Javascript Object with Functions into a String)

我今天遇到了一个情况,我需要通过HTTP访问一个Javascript文件。 实际程序与NodeJS一起运行,位于/ home /目录之外。

我试图访问javascript文件的原因是它有一个我经常使用的函数列表,并希望将它们与PhantomJS一起使用(基本上将它注入不同的网站)。

我能够通过将整个节点移动到一个可访问的文件夹并让htaccess拒绝访问除1个文件之外的所有内容来使其工作,但我很好奇是否有人会知道:

是否可以获取整个对象(函数和预设值)并将它们输出为字符串(就像导航到file.js页面一样)。 这样我就可以创建一个HTTP页面,发送正确的头文件,并基本上创建一个可访问的JS页面。

我环顾四周,但无法找到任何关于实际逐字输出对象的信息。


I came across a situation today where I needed a single Javascript file to be accessible through HTTP. The actual program was running with NodeJS and was outside of the /home/ directory.

The reason I was trying to access the javascript file was it has a list of functions that I use often, and wanted to utilize them with PhantomJS (essentially injecting it into a different website).

I was able to get it to work by moving the entire node into an accessible folder and having htaccess deny access to everything except 1 file, but I am curious if anyone would know:

Would it be possible to take an entire object (functions and preset values) and output them as a string (same as if you navigated to a file.js page). This way I could create an HTTP page, send the proper headers and essentially create an accessible JS page.

I looked around but couldn't find any information on actually outputting a object verbatim.

更新时间:2023-02-03 17:02

最满意答案

将用户Houshalter的答案检查到将对象转换为字符串的问题

所有答案提供了如何将没有函数的对象转换为字符串的不同示例 但他解释了如何使用包含函数的对象来做到这一点。


Check this answer from user Houshalter to the question Converting an object to a string.

All answers provide different examples how to convert object without function to string. But he explains how to do that with object which contains also functions.

相关问答

更多

相关文章

更多

最新问答

更多
  • 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
  • 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
  • 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
  • ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
  • Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
  • 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
  • 功能包装避免重复(wrap of functions avoid duplicating)
  • Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
  • 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
  • VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
  • 大学电脑四级对初学者来说要多久能过
  • 特殊字符删除?(Special characters remove?)
  • Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
  • 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
  • Javaweb开发,技术路线是什么?该怎么写?
  • JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
  • 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
  • Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
  • 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
  • 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
  • “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
  • maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
  • 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
  • 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
  • java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
  • 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
  • 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
  • 嵌套的模板可能性(Nested template possibilities)
  • 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
  • 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)