使用"whose"在自动化Javascript中的数组上 [英] Using "whose" on arrays in Javascript for Automation

查看:97
本文介绍了使用"whose"在自动化Javascript中的数组上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用脚本编辑器播放新的JS,实现自动化.我在以下的最后一行出现错误:

Playing with the new JS for automation using Script Editor. I'm getting an error on the final line of the following:

var iTunes = Application("iTunes");
var sources = iTunes.sources();
var library = sources.whose({name : "Library"});

确认source数组符合预期(两个元素,一个带有name"Library",另一个带有"Internet Radio").但是最后一行用Error on line 3: TypeError: undefined is not a function (evaluating 'sources.whose({name : "Library"})')阻塞了.

Confirmed that the sources array is as expected (two elements, one with name "Library" and one "Internet Radio"). But that final line chokes with Error on line 3: TypeError: undefined is not a function (evaluating 'sources.whose({name : "Library"})').

据我所知,我是

As far as I can tell, I'm using the right syntax for the whose function. (I also tried with an explicit _equals clause to the same result.) What am I doing wrong?

推荐答案

现在可以如理论所预期的那样工作.

This now works as theory would predict.

(function () {
    'use strict';

    var iTunes = Application('iTunes'),
        filtered = iTunes.sources.whose({
            name: 'Library'
        });

    return filtered().length;

})();

这篇关于使用"whose"在自动化Javascript中的数组上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆