hal.js
function Link (rel, value) {
    if (!(this instanceof Link)) {
      return new Link(rel, value);
    }

    if (!rel) throw new Error('Required <link> attribute "rel"');

    this.rel = rel;

    if (typeof value === 'object') {

      // If value is a hashmap, just copy properties
      if (!value.href) throw new Error('Required <link> attribute "href"');
      var expectedAttributes = ['rel', 'href', 'name', 'hreflang', 'title', 'templated', 'icon', 'align', 'method'];
      for (var attr in value) {
        if (value.hasOwnProperty(attr)) {
          if (!~expectedAttributes.indexOf(attr)) {
            // Unexpected attribute: ignore it
            continue;
          }
          this[attr] = value[attr];
        }
      }

    } else {

      // value is a scalar: use its value as href
      if (!value) throw new Error('Required <link> attribute "href"');
      this.href = String(value);

    }
  }
function Link (rel, value) {
    if (!(this instanceof Link)) {
      return new Link(rel, value);
    }

    if (!rel) throw new Error('Required <link> attribute "rel"');

    this.rel = rel;

    if (typeof value === 'object') {

      // If value is a hashmap, just copy properties
      if (!value.href) throw new Error('Required <link> attribute "href"');
      var expectedAttributes = ['rel', 'href', 'name', 'hreflang', 'title', 'templated', 'icon', 'align', 'method'];
      for (var attr in value) {
        if (value.hasOwnProperty(attr)) {
          if (!~expectedAttributes.indexOf(attr)) {
            // Unexpected attribute: ignore it
            continue;
          }
          this[attr] = value[attr];
        }
      }

    } else {

      // value is a scalar: use its value as href
      if (!value) throw new Error('Required <link> attribute "href"');
      this.href = String(value);

    }
  }
function Link ( rel , value ) { if ( ! ( this instanceof Link ) ) { return new Link ( rel , value ) ; } if ( ! rel ) throw new Error ( 'Required <link> attribute "rel"' ) ; this . rel = rel ; if ( typeof value === 'object' ) { // If value is a hashmap, just copy properties if ( ! value . href ) throw new Error ( 'Required <link> attribute "href"' ) ; var expectedAttributes = [ 'rel' , 'href' , 'name' , 'hreflang' , 'title' , 'templated' , 'icon' , 'align' , 'method' ] ; for ( var attr in value ) { if ( value . hasOwnProperty ( attr ) ) { if ( ! ~ expectedAttributes . indexOf ( attr ) ) { // Unexpected attribute: ignore it continue ; } this [ attr ] = value [ attr ] ; } } } else { // value is a scalar: use its value as href if ( ! value ) throw new Error ( 'Required <link> attribute "href"' ) ; this . href = String ( value ) ; } }
Link to another hypermedia
@param String rel → the relation identifier
@param String|Object value → the href, or the hash of all attributes (including href)
Link to another hypermedia