Skip to main content

Posts

Showing posts with the label this in JavaScript

What is ‘this’ in JavaScript?

Hello everyone, today's I am going to share a basic and very confusing concepts that is called 'this' keyword :) The  'this' keyword  behaves a little differently in  JavaScript  compared to other languages. In most of the other languages, ' this ' keyword is a reference to the current object instantiated by the classes  and methods.  In the JavaScript  languages , 'this' keyword refers to the object which 'owns' the method, but it depends on how a function is called. The examples in details as given below. //Global Scope in JavaScript //In the below example, ‘this’ keyword refers to the global object. window .sms = "Hi, I am window object" ; console .log ( window .sms); console .log (this.sms); // Hi, I am window object. console .log ( window === this); // Its return true. //Calling a Function in JavaScript //In the below example, ‘this’ keyword remains the global object if we are calling a function. wi...

Understanding JavaScript Inheritance with Example [How To]

How to “ Achieve Inheritance ”in JavaScript? In the JavaScript , we can implement the Inheritance using the some alternative ways and we can’t define a class keyword but we create a Constructor function and using new keyword achieves it.   The some Alternative ways As, 1.       Pseudo classical Inheritance 2.       Prototype Inheritance Pseudo  classical   Inheritance   is the most popular way. In this way, create a constructor function using the new operator and add the members function with the help for constructor function prototype. The  Prototype  based  programming is a technique of object oriented programming. In this mechanism we can reuse the exiting objects as prototypes.  The prototype inheritance also known as prototypal,  classless or instance based inheritances. Example as, // Create a helper function. if ( typeof Object .create !== 'functio...