Home > Web Front-end > JS Tutorial > Detailed analysis of the use of apply method in js_javascript skills

Detailed analysis of the use of apply method in js_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:17:45
Original
1028 people have browsed it

1. The general approach to object inheritance is to copy: Object.extend
The implementation of prototype.js is:

Copy the code The code is as follows:

Object.extend = function(destination, source) {
for (property in source) {
destination[property ] = source[property];
}
return destination;
}

In addition, there is another method, which is: Function.apply (of course using Function. You can also call)

The apply method can hijack the method of another object and inherit the properties of another object

Function.apply(obj, args) method can receive two parameters

obj: This object will replace this object in the Function class

args: This is an array, which will be passed as parameters to Function (args-->arguments)

apply demonstration code is as follows:

Copy code The code is as follows:

Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template