जावास्क्रिप्ट में एक विधि वस्तुओं पर की जाने वाली क्रिया है। एक जावास्क्रिप्ट विधि में एक फ़ंक्शन परिभाषा होती है, जिसे एक संपत्ति मान के रूप में संग्रहीत किया जाता है।
उदाहरण
जावास्क्रिप्ट में एक विधि को परिभाषित करने के लिए एक उदाहरण देखते हैं
लाइव डेमो
<!DOCTYPE html>
<html>
<body>
<h3 id="myDept"></h3>
<script>
var department = {
deptName: "Marketing",
deptID : 101,
deptZone : "North",
details : function() {
return "Department Details<br>" + "Name: " + this.deptName + " <br>Zone: " + this.deptZone + "<br>ID: " + this.deptID;
}
};
document.getElementById("myDept").innerHTML = department.details();
</script>
</body>
</html>