-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubFunction.html
50 lines (39 loc) · 1.2 KB
/
SubFunction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<html>
<head>
<script type ="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
<title></title>
</head>
<body>
<script type ="text/javascript">
// Applies when you want to change JQuery functions
$(function() {
var animal = {
eat: function() {console.log("I'm eating");}
}
var dog = {
bark: function() {console.log("I'm barking");}
}
var cat = {
meow: function() {console.log("meow");}
}
// In this case we redefine extend function and set only two input parameters instead of multiple parameters
var sub = $.sub();
sub.old_extend = sub.extend;
sub.extend = function (target, source) {return sub.old_extend(true, target, source);}
var catDog = {};
// Third and fourth parameters will be ignored
sub.extend(catDog, cat, dog, animal);
console.log(catDog.eat); // indefined
console.log(catDog.bark);// indefined
console.log(catDog.meow); // function
var catDog = {};
// Original extend function will be pay attention to third and fourth paramaters
$.extend(catDog, cat, dog, animal);
console.log(catDog.eat);// function
console.log(catDog.bark);// function
console.log(catDog.meow);// function
});
</script>
<h1>Sub demo</h1>
</body>
</html>