Practical guides, tutorials, and insights from years of building web and desktop applications. Check out code examples you can actually use!
Method of a Function in Javascript
A function can have its own methods - strange but true. Why? Because everything in Javascript is an object and object can have methods. Consider - function getSum(x, y) { return x + y; } console.log(getSum(1, 2)); //3 console.log(getSum.call(this, 1, 2)); //3 The first call to getSum is as expected. The second call uses a method called call and passes this as the argument along with the two numbers. This is equivalent to the first call. Or, use call’s friend apply - ...