Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 1.69 KB

File metadata and controls

77 lines (55 loc) · 1.69 KB

Task

Create a new "BetterUser" type that extends "User" by overriding the User's .toString method.

Your exported function will be passed the constructor function for a "User" type that looks like this:

/**
 * User Constructor.
 *
 * @param title {String} Title for User, e.g. 'Mr.', 'Mrs.', 'Dr.', etc.
 * @param name {String} Name of User e.g. 'John Smith'
 */

function User(title, name) {
  this.title = title
  this.name = name
  console.info('NEW USER: ' + this)
}

/**
 * Creates full display name for a user.
 * @return {String} Display name
 */

User.prototype.displayName = function() {
  return this.title + ' ' + this.name
}

/**
 * @return {String} Formatted name & title
 */

User.prototype.toString = function() {
  return '[User:'+this.displayName()+']'
}

Note: you do not need to copy this into your solution.

Example

From your exported function, return a BetterUser constructor function that extends User with a custom toString method that works like so:

var joe = new BetterUser('Mr.', 'Joe Smith') // pass in title and name
console.log('Hello ' + joe) // 'Hello [BetterUser: Mr. Joe Smith]'

Conditions

  • Don't call the User constructor unnecessarily!
  • Don't use __proto__
  • Do not create any unecessary functions e.g. helpers.

Resources

Boilerplate

// User is a constructor
function upgradeUser(User) {

  // EDIT THESE AS NECESSARY
  function BetterUser() {

  }

  return BetterUser
}

module.exports = upgradeUser