JSC seems like the simpler-and-easier,更便携,并且几乎是通用安装的-可以替代世界上的node.js。我已经能够弄清楚基础知识,但是几乎有nada浮在上面(为什么?),所以这是一个简单的问题,我希望有人可以澄清。

我在一个.js文件中有一个不错的littlejavascript“类”,它的开头是这样的... BTW, it takes a Hex Color code and spits out a "named" color. Neat.示例用法:

<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

但是,对于我的一生,我无法弄清楚如何通过此变量来传递一些变量。

就像,我只是想从2040808080a0404060a0a0a0606080c0c0c0a0a0a0606060808080404040c0e080a0e06080c020e0f0a0a0e04020202060a0e060c0f0a0a0a0a0e0f0202020606060a0a0a0404020604020f0c040202020中获取回调
 但似乎无法扭转局面。-e选项看起来很有希望,但无济于事。

多年来,已经有很多奇怪的小任务被javascript处理了,将它们交给这个家伙会很棒。.这个比喻特洛伊木马可能已经安装在潜在的客户端计算机上,甚至可以运行了。尽管这件事无处不在,但文档却像出席史蒂夫·鲍尔默粉丝俱乐部会议一样稀疏。

就是说,哈哈,这个JSC上仅有的半有用信息片段之一是来自7年前一位MS员工的帖子,该帖子建议...标题为“ 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的冒口感到困惑。最近人们,因为这绝对是个老新闻...为什么这个运行时环境总是对当前的热门主题解决方案po之以鼻? JSC很烂吗?告诉我,姐妹的女朋友。 ∀Ⓛ∃✖

最佳答案

以下似乎有效:

# 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/

10-07 19:56