4

In Ruby, in order to get the absolute cleanest inheritance chain, you can inherit from BasicObject instead of Object. This way you don't have an object with methods you don't necessarily want (the methods that are part of Object.prototype).

Does JavaScript have a similar means of defining a basic object?

function Person(name){
    this.name = name
}
var mac = new Person('Mac')
delete mac.toString        //does not work
delete mac.hasOwnProperty  //does not work

Once you instantiate an object via a constructor function, it is not possible to delete properties from the object if those properties are actually methods found on the prototype.

I don't want these methods on my object.

1 Answer 1

5

You can create an object with no properties at all by calling Object.create(null).

You can then set that as a function's prototype.
(instead of the default prototype, which starts as Object.create(Object.prototype).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.