如何通过终端或其他方式将参数传递给 JavaScriptCore/Console?

发布于 2024-11-27 15:04:26 字数 2378 浏览 0 评论 0原文

JSC 似乎更简单 - 并且- 更简单,更便携,并且准通用安装 - 显然是世界上 Node.js 的替代品......我已经能够弄清楚基础知识,但几乎没有什么关于它的信息它(为什么?),所以这是一个简单的问题,我希望有人能够澄清..

我在 .js 文件中有一个很好的小javascript“类”,它的开头是这样的... 顺便说一句,它需要一个十六进制颜色代码并吐出一个“命名”颜色。整洁。 示例用法:

<script type="text/javascript" src="ntc.js"></script>
<script type="text/javascript">
var n_match  = ntc.name("#6195ED");
    n_rgb        = n_match[0]; // This is the RGB value of the closest matching color
    n_name       = n_match[1]; // This is the text string for the name of the match
    n_exactmatch = n_match[2]; // True if exact color match, False if close-match
alert(n_match);
</script>

代码的开头和结尾如下...

var ntc = {
     init: function() {
     var color, rgb, hsl;
  ⤹
}
ntc.init();

我能够在本文档的底部处硬编码一些值,无需任何混乱或大惊小怪。 ,像这样...

var n_match = ntc.name("#000000");
print(n_match);

并从终端简单轻松地运行代码...

/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc -d ntc.js ↩

#000000,Black,true

但是,对于我的一生,我不知道如何通过这个傻瓜一些变量..

就像,我只想得到一个回调<代码>204080 8080a0 404060 a0a0a0 606080 c0c0c0 a0a0a0 606060 808080 404040 c0e080 a0e060 80C020 e0f0a0 a0e040 202020 60a0e0 60c0f0 a0a0a0 a0e0f0 202020 606060 a0a0a0 404020 604020 f0c040 202020 但似乎无法扭转它的手臂。 -e 选项看起来很有希望,但无济于事。

多年来,JavaScript 已经改变了许多奇怪的、小众的任务来处理,如果能把它们交给这个家伙就好了。象征性的特洛伊木马是它可能已经安装了,甚至可能已经安装了可运行 - 在潜在的客户端计算机上。尽管这个东西无处不在,但文档却像参加史蒂夫·鲍尔默粉丝俱乐部会议一样稀疏……

也就是说,哈哈,这是这个 JSC 上唯一半有用的信息片段之一 em> 来自一位 MS 员工 7 年前的帖子,该帖子建议...标题为“Commandline.js”,

import System;
// This function reads the commandline arguments and prints them
function PrintCommandLineArguments() {
    var args:String[] = System.Environment.GetCommandLineArgs();
    var iValue:int;
// Print the command-line arguments    
for (iValue in args)
    Console.WriteLine(args[iValue]);
}
PrintCommandLineArguments(); 

我无法让它工作,但必须有一种方式,聪明的裤子……哦还有坦率地说,这让我对最近所有服务器端 JS 人员都在胡言乱语感到更加困惑,因为这件事绝对是旧闻了……为什么这个运行时环境会受到青睐无论如何,当前的热门话题解决方案? JSC 很烂吗?姐妹们,帮我指点一下吧。 ∀Ⓛ∃✖

JSC seems like the simpler-and-easier, more portable, and quasi-universally-installed - obvious alternative to the node.js's of the world... I have been able to figure out the basics, but there is almost nada floating around out there about it (why?), so here's a simple problem I'm hoping someone can clarify..

I have a nice littlejavascript "class" in a .js file that starts out like this... BTW, it takes a Hex Color code and spits out a "named" color. Neat. Sample Usage:

<script type="text/javascript" src="ntc.js"></script>
<script type="text/javascript">
var n_match  = ntc.name("#6195ED");
    n_rgb        = n_match[0]; // This is the RGB value of the closest matching color
    n_name       = n_match[1]; // This is the text string for the name of the match
    n_exactmatch = n_match[2]; // True if exact color match, False if close-match
alert(n_match);
</script>

The code starts out with, and ends like so...

var ntc = {
     init: function() {
     var color, rgb, hsl;
  ⤹
}
ntc.init();

I am able, with little muss or fuss, to hardcode some values, at the BOTTOM of this document, like so...

var n_match = ntc.name("#000000");
print(n_match);

and run the code simply and easily from a terminal...

/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc -d ntc.js ↩

#000000,Black,true

However, for the life of me, I cannot figure out how to pass this sucker some variables..

Like, i just wanna get a callback from 204080
8080a0
404060
a0a0a0
606080
c0c0c0
a0a0a0
606060
808080
404040
c0e080
a0e060
80c020
e0f0a0
a0e040
202020
60a0e0
60c0f0
a0a0a0
a0e0f0
202020
606060
a0a0a0
404020
604020
f0c040
202020

but can't seem to twist its arm.. The -e option looked promising, but to no avail.

There are SOO many weird, niche tasks javascript has mutated to handle over the years, it would be great to hand them off to this guy.. The figurative trojan horse being that it's probably already installed, maybe even runnable - on potential client machines. As ubiquitous as this thing is though, the documentation is as sparse as the attendance at a Steve Ballmer fan-club meeting...

That said, lol, one of the only semi-useful snippets of info on this JSC was from a posting by an MS employee, from 7 years ago, that suggested... with the title "Commandline.js"

import System;
// This function reads the commandline arguments and prints them
function PrintCommandLineArguments() {
    var args:String[] = System.Environment.GetCommandLineArgs();
    var iValue:int;
// Print the command-line arguments    
for (iValue in args)
    Console.WriteLine(args[iValue]);
}
PrintCommandLineArguments(); 

I couldn't get that to work, but there has to be a way, smarty pants'... Oh and frankly, this just adds to my confusion over the frothing at the mouth that has taken hold of all the server-side JS people of late, as this thing is decidedly old news... Why was this runtime environment poo-pooed in favor of the current hot-topic solutions, anyways? Does JSC suck? Clue me in, sister girlfriends. ∀Ⓛ∃✖

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作业与我同在 2024-12-04 15:04:26

以下似乎有效:

# using Bash on Mac OS X 10.6.7
sudo ln -is /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /usr/local/bin

# simple example to print passed arguments
jsc --help   # Usage: jsc [options] [files] [-- arguments]
jsc <(echo 'print(arguments[0]); print(arguments);') -- one two three


# http://chir.ag/projects/ntc/
curl -L -O http://chir.ag/projects/ntc/ntc.js
echo '
for(var i in arguments) {
   var n_match = ntc.name(arguments[i]);
   print(n_match);
}
' >> ntc.js

jsc ntc.js -- 204080 8080a0 404060 a0a0a0 606080 c0c0c0 a0a0a0 606060 808080 \
              404040 c0e080 a0e060 80c020 e0f0a0 a0e040 202020 60a0e0 60c0f0 \
              a0a0a0 a0e0f0 202020 606060 a0a0a0 404020 604020 f0c040 202020


# For more information on using javascript from the command line see, for example: 
# - http://www.phpied.com/javascript-shell-scripting/
# - http://littlecomputerscientist.wordpress.com/2008/12/19/command-line-scripting-with-javascript/
# - http://littlecomputerscientist.wordpress.com/2008/12/20/improving-spidermonkeys-load-for-command-line-javascript/

The following seems to work:

# using Bash on Mac OS X 10.6.7
sudo ln -is /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /usr/local/bin

# simple example to print passed arguments
jsc --help   # Usage: jsc [options] [files] [-- arguments]
jsc <(echo 'print(arguments[0]); print(arguments);') -- one two three


# http://chir.ag/projects/ntc/
curl -L -O http://chir.ag/projects/ntc/ntc.js
echo '
for(var i in arguments) {
   var n_match = ntc.name(arguments[i]);
   print(n_match);
}
' >> ntc.js

jsc ntc.js -- 204080 8080a0 404060 a0a0a0 606080 c0c0c0 a0a0a0 606060 808080 \
              404040 c0e080 a0e060 80c020 e0f0a0 a0e040 202020 60a0e0 60c0f0 \
              a0a0a0 a0e0f0 202020 606060 a0a0a0 404020 604020 f0c040 202020


# For more information on using javascript from the command line see, for example: 
# - http://www.phpied.com/javascript-shell-scripting/
# - http://littlecomputerscientist.wordpress.com/2008/12/19/command-line-scripting-with-javascript/
# - http://littlecomputerscientist.wordpress.com/2008/12/20/improving-spidermonkeys-load-for-command-line-javascript/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文