JavaScript Basics: Object.getPrototypeOf and Object.setPrototypeOf

in #javascript7 years ago

These functions, as is evident from their names, enable you to get and set the prototype of an object. In light of the availability of these functions, the use of the __proto__ property is generally discouraged.

Here is an example:

    let objA = {};
    let objB = {};
    Object.setPrototypeOf(objA, objB);
    Object.getPrototypeOf(objA) === objB; // true

The prototype of an object can be null. So you can assign null as the prototype of an object.

It should be noted that many JavaScript engines perform optimizations based on the value of [[prototype]] internal property. Changing the prototype with Object.setPrototypeOf will have adverse effects on those optimizations even after the prototype has been set. Therefore, in cases where performance is very important, the use of Object.create is more efficient than changing the prototype of an object with Object.setPrototypeOf.


Related Posts

Sort:  

thanks for the info , you choosed a best way for publishing your posts, if u use many topics then u can be ueful for large steemians,, javascript is one of them , keep it on and good luck

Thanks a lot.

Nice job. and missing idiom tutorial. :p

خیلی خوب و مفید. ممنون

Thank you sir @ghasemkiani . Really I need such information. I am completing a course. Web designing. Javescript is very much important foor this course.

Thanks sir @ghasemkiani for sharing the info of Javascript

Helpful for learing javascript. Thanks for sharing.

great change. i will appreciate your efforts in programming

nice post friends with beautiful content. carry on your activity.

that's pretty cool to know....

Your bolg alwyas educAtional for us

দেবেনা নাকি?

Dibe pore holeo dibe

It increases my program skill.So this is very helpful for me.Give a complete part tutorial of javascript.
Thanks a lot sir

i like u..becouse your all post are helpfull... carry on sir

your post is very good to me dear
i love your post,,,

I much appreciated you are very honest with your work.
Your all lactures i save I know they all very usefull next lavel.
Thanks for sharing blog.
Stay blessed @ghasemkiani

I am new on steemit. I heard about you from my brother. i would like to join you sir.

Thanks for sharing your knowledge with us.Its be more helpful for many students like me :)

@ghasemkiani JavaScript is an interesting language. You can play with this. Just keep sharing.

Really I need such information. I am completing a course. Web designing. Javescript is very much important foor this course.,,and i am really big friend of you

Nice job. and missing idiom tutorial. :p

Dear sir..
Your post alwayas educational for us..which are really helpful for me..Javescript is very much important for konwing this course..
thank you sir for ur konwledge sharing us..

nice post my friend

Thank you sir @ghasemkiani . Really I need such information. I am completing a course. Web designing. Javescript is very much important foor this course.

Nice post. I miss your idioms with persian translation.

you are really a good progammer

very informative post @ghasemkiani you are actually doing great work

so informative post...over all..
nice post...
thanks for sharing dear. ..
carry on your activity. ..

that's pretty cool to know...

your activity is good with programming
go ahed and keep it up

so informative post

Good Post.

really great post & informative post....

Thanks sir @ghasemkiani for sharing the info of Javascript