Copy properties - Node.js Object

Node.js examples for Object:Property

Description

Copy properties

Demo Code


function copyProperties ( sourceObject, destinationObject, propertyNames /*= getOwnProperties( sourceObject ) */)
{
  if ( propertyNames === undefined )
    propertyNames = getOwnProperties( sourceObject );
    /*  w  w w. j  ava  2 s  .  c  o  m*/
  iterateArray( propertyNames, function ( propertyName )
  {
    if ( sourceObject[ propertyName ] !== undefined )
      destinationObject[ propertyName ] = sourceObject[ propertyName ];
  });
}

function getOwnProperties ( object )
{
  var array = [];
  for ( var propertyName in object )
    if ( object.hasOwnProperty( propertyName ) )
      array.push( propertyName );
  return array;
}

Related Tutorials