Alternate method to splice function in JavaScript

Array.prototype.splice is fully defined in ECMA-262 §15.4.4.12, so use that as your spec and write one. e.g.

15.4.4.12 Array.prototype.splice (start, deleteCount [ , item1 [ ,item2 [ , … ] ] ] )

When the splice method is called with two or more arguments start, deleteCount and (optionally) item1, item2, etc., the deleteCount elements of the array starting at array index start are replaced by the arguments item1, item2, etc. An Array object containing the deleted elements (if any) is returned. The following steps are taken:...

You will probably have to create a new array, copy the members up to start from the old array, insert the new members, then copy from start + deleteCount to the end to the new array.

Edit

Here is an amended splice, the first I posted was incorrect. This one splices the array passed in and returns the removed members. It looks a bit long but I tried to keep it close to the spec and not assume support for any complex Array methods or even Math.max/min. It can be simplified quite a bit if they are.

If push isn't supported, it can be replaced fairly simply too.

function arraySplice(array, start, deleteCount) {
  var result = [];
  var removed = [];
  var argsLen = arguments.length;
  var arrLen = array.length;
  var i, k;

  // Follow spec more or less
  start = parseInt(start, 10);
  deleteCount = parseInt(deleteCount, 10);

  // Deal with negative start per spec
  // Don't assume support for Math.min/max
  if (start < 0) {
    start = arrLen + start;
    start = (start > 0)? start : 0;
  } else {
    start = (start < arrLen)? start : arrLen;
  }

  // Deal with deleteCount per spec
  if (deleteCount < 0) deleteCount = 0;

  if (deleteCount > (arrLen - start)) {
    deleteCount = arrLen - start;
  }

  // Copy members up to start
  for (i = 0; i < start; i++) {
    result[i] = array[i];
  }

  // Add new elements supplied as args
  for (i = 3; i < argsLen; i++) {
    result.push(arguments[i]);
  }

  // Copy removed items to removed array
  for (i = start; i < start + deleteCount; i++) {
    removed.push(array[i]);
  }

  // Add those after start + deleteCount
  for (i = start + (deleteCount || 0); i < arrLen; i++) {
    result.push(array[i]);
  }

  // Update original array
  array.length = 0;
  i = result.length;
  while (i--) {
    array[i] = result[i];
  }

  // Return array of removed elements
  return removed;
}