Robert Bosch – Front end / Javascript developer interview questions and answer

Sharag's Tech Interview HELP

1)explain javascript inheritance ?

JavaScript does not have “methods” in the form that class-based languages define them. In JavaScript, any function can be added to an object in the form of a property. An inherited function acts just as any other property When an inherited function is executed, the value of this points to the inheriting object, not to the prototype object where the function is an own property.

var o = { a: 2, m: function(b){ return this.a + 1; } };

console.log(o.m()); // 3 // When calling o.m in this case, ‘this’ refers to o

var p = Object.create(o); // p is an object that inherits from o

p.a = 12; // creates an own property ‘a’ on p console.log(p.m()); // 13 // when p.m is called, ‘this’ refers to p. // So when p inherits the function m of o, ‘this.a’ means p.a, the own property ‘a’…

View original post 987 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s