Method trong JavaScript là hành động thực hiện trên đối tượng. Nó là thuộc tính (property) mang hàm, ví dụ: employee.name, employee.department.
Truy cập method: object.method(). Ví dụ: employee.details().
Ví dụ
<html>
<head>
<script>
var employee = {
empname: "Amit",
department: "Marketing",
id: 001,
details: function() {
return this.empname + " with ID: " + this.id;
}
};
document.write(employee.details());
</script>
</head>
</html>
Kết quả
