Object Creation and Manipulation Functions in JavaScript

in #javascript7 years ago (edited)

JavaScript has undergone several incarnations during its life. These transformations have made it possible to modify and fine-tune the object creation and manipulation process. Besides the usual way to create objects with constructor functions and to assign prototypes to those functions, you can directly create objects from a prototype, define properties with the desired descriptors, and also control the enumerability or configurability of the properties.

The functions that are used for this purpose are situated on the Object constructor. For example, in order to create an object from an arbitrary prototype, you can use the Object.create function. Here is a simple example:

    const dog = {
        bark() {
            console.log("Woof-woof!");
        },
    };
    let pluto = Object.create(dog);
    pluto.bark();

This is a list of the functions used for object creation or manipulation that are accessible through Object:

    create
    assign
    defineProperty
    defineProperties
    getPrototypeOf
    setPrototypeOf
    getOwnPropertyDescriptor
    getOwnPropertyDescriptors
    getOwnPropertyNames
    getOwnPropertySymbols
    is
    seal
    freeze
    preventExtensions
    isExtensible
    isSealed
    isFrozen
    keys
    entries
    values

There are a few methods on Object.prototype that are related to these tasks:

    hasOwnProperty
    isPrototypeOf
    propertyIsEnumerable

The following property and methods on Object.prototype are deprecated and should not be used:

    __proto__
    __defineGetter__
    __defineSetter__
    __lookupGetter__
    __lookupSetter__

Evidently, each of the functions that were listed in this post are very important and need extensive coverage. I hope to start a series of posts for explaining these functions.

Sort:  

Correct, __proto__ is not a part of the specification. But still, we can use getPrototypeOfwhich does the same. So in your example:
Object.getPrototypeOf(pluto) === dog

Exactly. The new functions make those old mechanisms unnecessary, and I think they look ugly with all those underlines.

I think the major advantage of this "proto" property is the key role in javascript property delegation mechanism learning process, as we can quickly navigate prototype chain objects using it. Nothing more.

Multi talented people like you @ghasemkiani should be prominent according to their skills so that they can deliver maximum output towards community. All the best & Stay blessed!

Thank you. I am just a curious person.

I love programming a lot.
javascript is the best programming language
I learn so manything from your post.
Thank you so much dear @ghasemkiani for share this topic with us.

The Java program is a difficult language.i like this post.
thanks for sharing @ghasemkiani

hey dear @ghasemkiani relly excited java script. i hope you share next like tutorial.
And Thanks.

Well Done Bro.

I learned a lot about reading this post. But the Java script is very difficult. thanks for sharing @ghasemkiani

I love programming too much. Javascript is a great programming language.
this post is very helpful for us.
Thank you so much for sharing your JavaScript coding expertise with us @ghasemkiani

Great work done by you @ghasemkiani, you all the articles related to education which no doubt guide the student as well educate them.

Are you a programer too?

Yes, I mostly program in JavaScript and Java.

Wow!!!! What's your main job? How many job you do?

As the old saying goes, I wear many hats!

Great. Keep it up sir.

Programming is my favourite also. web Programming, Javascript & CSS is also my favourite. PHP and Javascript coding is very interesting for me. thanks for this post sharing with us @ghasemkiani

Dear I like It!This post is very Helpful for us. I am so glad for your post @ghasemkiani .Finally I wishing you regards for your regard.

Dear @ghasemkiani i think you run next seris i love pograming . & thanx for sharing.

hey dear @ghasemkiani relly excited java script i hope you share next like tutorila. & thanx you so much for sharing .

Great work done by you @ghasemkiani, you all the articles related to education which no doubt guide the student as well educate them. Keep it up , our support alongwith you.

nice your post sir

Always love. appreciate and like your post...

Dear @ghasemkiani Thank you so much for your another content sharing:)

i loved this post

Ow i know this....✌✌✌

useful coding

Amazing post really nice.....I like it.thx for share😍

This post has received a 8.37 % upvote from @buildawhale thanks to: @ghasemkiani. Send at least 1 SBD to @buildawhale with a post link in the memo field for a portion of the next vote.

To support our daily curation initiative, please vote on my owner, @themarkymark, as a Steem Witness

i like your post dear.i waitting for your next post.
nice sharing @ghasemkiani