hal.js
function Resource (object, uri) {
    // new Resource(resource) === resource
    if (object instanceof Resource) {
      return object;
    }

    // Still work if "new" is omitted
    if (!(this instanceof Resource)) {
      return new Resource(object, uri);
    }

    // Initialize _links and _embedded properties
    this._links = {};
    this._embedded = {};

    // Copy properties from object
    // we copy AFTER initializing _links and _embedded so that user
    // **CAN** (but should not) overwrite them
    for (var property in object) {
      if (object.hasOwnProperty(property)) {
        this[property] = object[property];
      }
    }

    // Use uri or object.href to initialize the only required <link>: rel = self
    uri = uri || this.href;
    if (uri === this.href) {
      delete this.href;
    }

    // If we have a URI, add this link
    // If not, we won't have a valid object (this may lead to a fatal error later)
    if (uri) this.link(new Link('self', uri));
  }
function Resource (object, uri) {
    // new Resource(resource) === resource
    if (object instanceof Resource) {
      return object;
    }

    // Still work if "new" is omitted
    if (!(this instanceof Resource)) {
      return new Resource(object, uri);
    }

    // Initialize _links and _embedded properties
    this._links = {};
    this._embedded = {};

    // Copy properties from object
    // we copy AFTER initializing _links and _embedded so that user
    // **CAN** (but should not) overwrite them
    for (var property in object) {
      if (object.hasOwnProperty(property)) {
        this[property] = object[property];
      }
    }

    // Use uri or object.href to initialize the only required <link>: rel = self
    uri = uri || this.href;
    if (uri === this.href) {
      delete this.href;
    }

    // If we have a URI, add this link
    // If not, we won't have a valid object (this may lead to a fatal error later)
    if (uri) this.link(new Link('self', uri));
  }
function Resource ( object , uri ) { // new Resource(resource) === resource if ( object instanceof Resource ) { return object ; } // Still work if "new" is omitted if ( ! ( this instanceof Resource ) ) { return new Resource ( object , uri ) ; } // Initialize _links and _embedded properties this . _links = { } ; this . _embedded = { } ; // Copy properties from object // we copy AFTER initializing _links and _embedded so that user // **CAN** (but should not) overwrite them for ( var property in object ) { if ( object . hasOwnProperty ( property ) ) { this [ property ] = object [ property ] ; } } // Use uri or object.href to initialize the only required <link>: rel = self uri = uri || this . href ; if ( uri === this . href ) { delete this . href ; } // If we have a URI, add this link // If not, we won't have a valid object (this may lead to a fatal error later) if ( uri ) this . link ( new Link ( 'self' , uri ) ) ; }
A hypertext resource
@param Object object → the base properties
Define "href" if you choose not to pass parameter "uri"
Do not define "_links" and "_embedded" unless you know what you're doing
@param String uri → href for the <link rel="self"> (can use reserved "href" property instead)
A hypertext resource