can any one define methods on javascript, little bit in easy way as im new to this language ???
Asked
Active
Viewed 67 times
-9
-
1"Methods" are object properties which are functions. Nothing more, nothing less. – Madara's Ghost Sep 19 '15 at 11:22
-
Have you tried doing any research at all before posting this question? – jchamp Sep 19 '15 at 11:23
-
3Next time, take 5s to type "what is method in javascript" in your friend Google and you'll find plenty of interesting stuff, like : https://www.utexas.edu/learn/javascript/objects.html, http://sharkysoft.com/archive/1997/jsa/content/039.html or even SO answer : http://stackoverflow.com/questions/155609/difference-between-a-method-and-a-function – Stranded Kid Sep 19 '15 at 11:24
-
ask google before asking to anyone. – Hashir Hussain Sep 19 '15 at 11:26
1 Answers
0
Like this using inline object
var object = {
method: function() {
console.log('this is method');
}
};
object.method();
using contructor:
function Foo() {
this.method = function() {
console.log('this is method');
};
}
var object = new Foo();
object.method();
using prototype:
function Foo() {}
Foo.prototype.method = function() {
console.log('this is method');
};
var object = new Foo();
object.method();

jcubic
- 61,973
- 54
- 229
- 402