Method

Updated: 04/26/2017 by Computer Hope

methodIn programming, a method is a function that is a member of a class/object (in technical terms, it is bound to that class/object). The method has access to the variables and properties defined in the class/object and can perform tasks on any instances of the class/object. Below, is an example using JavaScript where an object named GPS is created, and includes a method named send_msg.

function GPS(msg) {
this.send_msg = function() {
window.alert(msg);
}
}
var lost = new GPS("You are lost!");
lost.send_msg();

The send_msg method sends a message stored with each instance of the GPS object as a pop-up alert to the user when run. In this case, when the code is run, the user gets a pop-up message that says "You are lost!".

Class, Object, Programming terms