- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我已经开始了一个项目,我需要使用 Adobe Indesign 和 ExtendScript 以编程方式从一系列 INDD 文件中提取一些数据。在这些程序中用于编写脚本的 Javascript 版本不支持我习惯使用的任何高阶函数(Array.reduce()
、Array.forEach()
、Array.map()
等...)。
有没有办法将此功能添加到 ExtendScript 中?我觉得我在一个四英尺高的天花板的房间里走来走去。
最佳答案
ExtendScript 似乎支持纯 Javascript 对象的原型(prototype)设计(但 not Indesign DOM objects ),因此可以使用 polyfill 来添加缺失的功能。 Polyfill 代码可以在 MDN 上的“Polyfill”下的相关方法页面上找到。这是一个例子:MDN Array.prototype.reduce() Polyfill .有许多方法的 polyfill,包括 Array.map()
、Array.indexOf()
、Array.filter()
和 Array.forEach()
.
要实现代码,只需在与脚本相同的文件夹中创建一个适当命名的文件(即 polyfill.js
或 reduce.js
)。将 MDN 中的 polyfill 代码复制到您刚刚创建的文件中,如下所示:
// Production steps of ECMA-262, Edition 5, 15.4.4.21
// Reference: http://es5.github.io/#x15.4.4.21
if (!Array.prototype.reduce) {
Array.prototype.reduce = function(callback /*, initialValue*/) {
'use strict';
if (this == null) {
throw new TypeError('Array.prototype.reduce called on null or undefined');
}
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
var t = Object(this), len = t.length >>> 0, k = 0, value;
if (arguments.length == 2) {
value = arguments[1];
} else {
while (k < len && !(k in t)) {
k++;
}
if (k >= len) {
throw new TypeError('Reduce of empty array with no initial value');
}
value = t[k++];
}
for (; k < len; k++) {
if (k in t) {
value = callback(value, t[k], k, t);
}
}
return value;
};
}
然后在脚本的开头添加以下行,适本地替换文件名:
#include 'polyfill.js';
行尾的分号没有包含在 Adobe 文档中,但我发现如果不加分号,有时 ExtendScript 会抛出错误,尤其是当您多次使用 #include
时.
关于javascript - 如何在 Indesign 脚本中使用 Array.reduce() 等高阶函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35276076/
我正在使用缺少 findall 的高阶 Prolog 变体. 还有一个关于实现我们自己的问题 findall这里:Getting list of solutions in Prolog . 低效的实现
我正在尝试使用 Flow 类型创建高阶组件,但在处理返回的组件类型时遇到了问题。 最小的例子: /* @flow */ import React from 'react'; type Props =
我想抽象化传递到我的数组的 reduce() 函数中的函数,使该函数成为通用的“最强大的 Array reducer”。为此,我想在 reduce() 参数中传入不同的特定函数,以便能够指定比较标准。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
将宏名称作为其他宏的参数来模拟高阶函数是否“安全”? 即我应该注意哪里才不会搬起石头砸自己的脚? 以下是一些片段: #define foreach_even(ii, instr) for(int ii
谁能给我解释一下下面的代码是怎么回事。该函数正在接收 n 作为参数,那么 m 来自哪里?整个代码令人困惑。如果有人可以解释一下? function greaterThan(n) { retur
我有一个 list ,例如: ["Hello", "Goodbye"] 我想使用 map在名单上; 我已经成功使用 map前: f = ("example" ++) 那么: map f ["Hello
我正在尝试通过在线书籍“Learn you a Haskell”来学习一些 Haskell,并且我有一个关于高阶函数的问题。 我看到了some examples我想做一些更高级的功能,但我不知道为什么
我正在学习更深入的 redux,并且在处理高阶 reducer 时遇到一些麻烦。 我试图使用一个简单的分页示例来了解它是如何工作的。 NB:下面的代码只是 Nodejs 上下文中 redux 的一个快
高阶函数是什么呢? 高阶函数英文名叫:Higher Order function ,一个函数可以接收一个或多个函数作为输入,或者输出一个函数,至少满足上述条件之一的函数,叫做高阶函数。 前言
我写了一个小的 R 代码片段来遍历包含马尔可夫链实现的向量,并返回观察到的给定顺序的转换。具体而言,假设我们对状态空间 $\mathcal{S}$ 的 2 次转换感兴趣。最终目标是以方便的形式存储计数
如您所见,我很难表达标题中的问题。 我有一个包含 li 的 ul,它本身包含一个 ul 和它自己的 li。 我希望仅第一个 li 元素而不是第二个 ul 中的元素。 如果你看this fiddle (
我是一名优秀的程序员,十分优秀!