With the basics out of the way, we'll now focus on object-oriented JavaScript (OOJS) . This article presents a basic view of object-oriented programming with an example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<input type="button" id="add" value="Add">
<input type="button" id="multipy" value="Multipy">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
var calculator = {
add : function(n1,n2)
{
alert(n1+n2);
},
multipy : function(n1,n2)
{
alert(n1*n2);
}
}
$('#add').click(function(){
calculator.add(2,3);
});
$('#multipy').click(function(){
calculator.multipy(2,3);
});
</script>
|