LoginSignup
9
10

More than 5 years have passed since last update.

JSXでUnderscore.jsとかjson2.jsを使う

Posted at

1.jsファイルをダウンロードしてくる

Underscore.js
http://underscorejs.org/underscore-min.js

JSON.js
https://github.com/douglascrockford/JSON-js

2.好きな場所に置く

どこでもいいのだけどESTのデフォルトの置き場が~/Documents/Adobe Scripts/だからその下にlibというフォルダを作って置いた。

  • ~
    • Documents
      • Adobe Scripts/
        • lib/
          • json2.js
          • underscore-min.js

3.JSXで読み込む

普通に。

test.jsx
(function(){
   var scriptdir = "~/Documents/Adobe Scripts";
   $.evalFile(scriptdir+"/lib/underscore-min.js");
   $.evalFile(scriptdir+"/lib/json2.js");
   $.writeln(_.isArray([])); // -> treu
   $.writeln(_.isObject(JSON.parse("{}"))); // -> true
}).call(this);

無名関数で書くときはきちんと.call(this)しないとJSXのグローバルオブジェクトである$.globalがスコープのthisに代入されないのでexportが上手くいかないことに注意。

4.まとめ

どうせできないだろと思っていたら思いの外簡単に外部jsを使うことができた。
これでPhotoshopの自動化が捗ると思う。

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10