I'm currently reading through this jquery masking plugin to try and understand how it works, and in numerous places the author calls the slice() function passing no arguments to it. For instance here the _buffer variable is slice()d, and _buffer.slice() and _buffer seem to hold the same values.
Is there any reason for doing this, or is the author just making the code more complicated than it should be?
//functionality fn
function unmaskedvalue($input, skipDatepickerCheck) {
var input = $input[0];
if (tests && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
var buffer = _buffer.slice();
checkVal(input, buffer);
return $.map(buffer, function(element, index) {
return isMask(index) && element != getBufferElement(_buffer.slice(), index) ? element : null; }).join('');
}
else {
return input._valueGet();
}
}
slicemethod is being used at the beginning of the function to backup the original array items before being modified by the function, this way the author has access to the positions, keys and values of the original array even after and while editing the array. This is indispensable when making a responsible string manipulating interface, as your example plugin. Complementing on @alex's comment, if it's there, there's a reason for it. Ctrl+F the source and look for where it's being accessed later on if you need a better understanding.