0

I know it's a very basic question, but since I am a beginner I have very limited knowledge about it. I tried to understand it by googling various online sources, but could not get a crystal clear view of it. Thanks in advance.

3
  • I would say function and method are synonyms in all languages, not just Javascript. There might be language lawyers here that will cite subtle differences, but that's how I think of them. Commented Dec 25, 2015 at 4:28
  • @duffymo: How you think of them is immaterial. How ES5 and ES6 specification thinks of them is the important bit. And there is a clear difference - only methods can be invoked on a target using the dot notation, setting this (or self, in other languages) in the process. Commented Dec 25, 2015 at 4:31
  • You're correct; my thinking is immaterial here. Thank you for the instruction. Commented Dec 25, 2015 at 13:35

1 Answer 1

2

A method, in JavaScript, is a function that is set on an object property; no more, no less.

window.f = function() {} // method of `window` a = { g: function() {} // method of `a` }; function x() { var h = function() {} // not a method, because it's in a local variable, // not in an object attribute var b = { i: h }; // method of `b` now. }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.