Nodejs Array Clone Int8Array clone

Here you can find the source of Int8Array clone

Method Source Code

(function(global){ "use strict";


Int8Array.prototype.clone =
Uint8Array.prototype.clone =
Uint8ClampedArray.prototype.clone =
Int16Array.prototype.clone =
Uint16Array.prototype.clone =
Int32Array.prototype.clone =
Uint32Array.prototype.copy =
Float32Array.prototype.clone =
Float64Array.prototype.clone =

function clone(){
  var l    = this.length,
      copy = new this.constructor(l);
  
  for( var i=0; i<l; i++ )
    copy[i] = this[i];//  ww  w .j a  va 2  s.c om
  
  return copy;
};



Array.isTypedArray = function isTypedArray(a){
  return a instanceof Int8Array        ||
         a instanceof Uint8Array       ||
         a instanceof Uint8ClampedArray||
         a instanceof Int16Array       ||
         a instanceof Uint16Array      ||
         a instanceof Int32Array       ||
         a instanceof Uint32Array      ||
         a instanceof Float32Array     ||
         a instanceof Float64Array;
};



Array.prototype.clone =
function clone(){
  var l    = this.length,
      copy = [];
  
  for( var i=0; i<l; i++ ){
    var x = this[i];
    if( Array.isTypedArray(x) ){
      copy[i] = i.clone();
    }else{
      copy[i] = Object.clone(x);
    }
  }
  
  return copy;
};


})(this);

Related

  1. clone(deep)
    'use strict';
    function clone_array(src, deep) {
      var result = [];
      var i, l = src.length;
      for (i = 0; i < l; i++) {
        if (deep)
          result.push(clone(src[i], deep));
        else
          result.push(src[i]);
    ...
    
  2. cloneReserva()
    Array.prototype.cloneReserva = function() {
       var arr = [];
       for(var i = 0; i < this.length ; i++){
           obj = {
             reservaId   : this[i].reservaId,      
              color       : this[i].color, 
              timeStart   : new Date(this[i].timeStart),  
              timeEnd     : new Date(this[i].timeEnd),  
              reservedBy  : this[i].reservedBy, 
    ...
    
  3. Clone()
    Array.prototype.Clone = function()
        var n = [];
        var s = this.constructor;
        for ( var i in this )
            if ( !s[ i ] )
                if ( this[ i ] != null && typeof this[ i ] == typeof [] )
                    n[ i ] = this[ i ].Clone();
    ...
    
  4. _clone()
    Array.prototype._clone = function() {
        var ar = [];
        for(var i = 0; i < this.length; i++) {
            ar.push(this[i]);
        return ar;
    
  5. deepClone()
    Array.prototype.deepClone = function () {
      return JSON.parse(JSON.stringify(this));
    };