Does Javascript have a BasicObject similar to Ruby?

In Ruby, to get an absolute clean inheritance chain, you can inherit from BasicObject instead of Object . Thus, you do not have an object with methods that you do not necessarily need (methods that are part of Object.prototype ).

Does JavaScript have a similar means of defining a base 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 create an instance of the object using the constructor function, the delete properties of the object cannot be found if these properties are actually found on the prototype.

I do not need these methods for my object.

+4
source share
1 answer

You can create an object without any properties by calling Object.create(null) .

You can then set this as a prototype function.
(instead of the default prototype that starts as Object.create(Object.prototype) .

+5
source

Source: https://habr.com/ru/post/1483434/


All Articles