JavaScript: How to Create Object with Parent X?

By Xah Lee. Date: . Last updated: .

Two ways to create a object with a specific parent.

Easy way:

var obj = Object.Create(my_parent)

〔►see JavaScript: Object.create

or, using a constructor, by the following steps:

  1. Define a function F with no return statement.
  2. Set the prototype property: F.prototype = my_parent
  3. Create the object. var obj = new F.

〔►see JavaScript: Operator “new”

〔►see JavaScript: How to Use Object.create() to Emulate Constructor?

Object and Inheritance Topic

  1. JavaScript: Object System Overview
  2. JavaScript: What's Object?
  3. JavaScript: Prototype and Inheritance
  4. JavaScript: Create Object
  5. JavaScript: Object Literal Expression
  6. JavaScript: Find Object's Prototype
  7. JavaScript: How to Create Object with Parent X?
  8. JavaScript: Prevent Adding Property
  9. JavaScript: Determine Type of Object
  10. JavaScript: Primitive Value Object Wrapper
  11. JavaScript: Clone, Deep Copy Object/Array
  12. JavaScript: Test Equality of Objects

  1. JavaScript: Object Object
  2. JavaScript: Object.prototype
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.