forked from preeti-14-7/JavaScript-Program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22problem.js
More file actions
19 lines (16 loc) · 776 Bytes
/
22problem.js
File metadata and controls
19 lines (16 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var someObject = {
myProperty : 'Foo',
myMethod : function(prefix, postfix) {
alert(prefix + this.myProperty + postfix);
}
};
someObject.myMethod('<', '>');
var someOtherObject = {
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>');
someObject.myMethod.apply(someOtherObject, ['<', '>']);
/*
Both .call() and .apply() functions are almost identical in their use, with a major exception in how arguments are passed to the function.
Because arguments are to be passed in the .call() method, it is compulsory to know about the function's arguments. On the other hand, the .apply() method is used when the number of arguments is unknown. The following example demonstrates using the two functions:
*/