Prototype - Enumerable pluck() 方法
此方法是对 collect() 方法常见用例的优化。为所有元素获取相同的属性。
语法
Iterator.pluck(propertyName);
此方法是对 collect() 方法常见用例的优化。为所有元素获取相同的属性。
Iterator.pluck(propertyName);
返回属性值数组。
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr = ['world', 'this', 'is', 'nice'].pluck('length');
alert("Test 1 : " + arr.inspect() );
// Returns [5, 4, 2, 4]
}
</script>
</head>
<body>
<p>单击按钮查看结果。</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
