src/js/method.js
function( target, attr ) {
    if ( typeof attr !== 'object' )  return
    var len = attr.length

    // Native `NamedNodeMap``:
    if (
      typeof attr[0] === 'object' &&
      'name' in attr[0]
    ) {
      for ( var i = 0; i < len; i++ ) {
        if ( attr[ i ].value !== undefined ) {
          target.setAttribute( attr[ i ].name, attr[ i ].value )
        }
      }

    // Plain object:
    } else {
      for ( var name in attr ) {
        if (
          attr.hasOwnProperty( name ) &&
          attr[ name ] !== undefined
        ) {
          target.setAttribute( name, attr[ name ] )
        }
      }
    }
    return target
  }
function( target, attr ) {
    if ( typeof attr !== 'object' )  return
    var len = attr.length

    // Native `NamedNodeMap``:
    if (
      typeof attr[0] === 'object' &&
      'name' in attr[0]
    ) {
      for ( var i = 0; i < len; i++ ) {
        if ( attr[ i ].value !== undefined ) {
          target.setAttribute( attr[ i ].name, attr[ i ].value )
        }
      }

    // Plain object:
    } else {
      for ( var name in attr ) {
        if (
          attr.hasOwnProperty( name ) &&
          attr[ name ] !== undefined
        ) {
          target.setAttribute( name, attr[ name ] )
        }
      }
    }
    return target
  }
function ( target , attr ) { if ( typeof attr !== 'object' ) return var len = attr . length // Native `NamedNodeMap``: if ( typeof attr [ 0 ] === 'object' && 'name' in attr [ 0 ] ) { for ( var i = 0 ; i < len ; i ++ ) { if ( attr [ i ] . value !== undefined ) { target . setAttribute ( attr [ i ] . name , attr [ i ] . value ) } } // Plain object: } else { for ( var name in attr ) { if ( attr . hasOwnProperty ( name ) && attr [ name ] !== undefined ) { target . setAttribute ( name , attr [ name ] ) } } } return target }
Set attributes all in once with an object.
Set attributes all in once with an object .