, .map() jQuery, , , jQuery . ( ):
var $collection = $('#qinfo p:even').map(function () {
return $(this).text();
});
var ucfirst = $collection.map(function () {
return this.replace(/^./, function (fst) {
return fst.toUpperCase();
});
}).get();
var prefixed = $collection.map(function () {
return 'prefix-' + this;
}).get();
console.log($collection.get());
console.log(ucfirst);
console.log(prefixed);
, , , . , .map() . , .map() . :
$.fn.ucfirst = function () {
return this.map(function () {
return this.replace(/^./, function (fst) {
return fst.toUpperCase();
});
});
};
$collection.ucfirst().each(function () {
console.log(this.toString());
});
It should be noted that it is .ucfirst()designed to work with collections of strings, which is beyond the scope of the original jQuery target.
source
share