1. call
Effect: Changes this point to call the function to pass in an argument.
Grammar:
Effect: Changes this point to call the function to pass in an argument.
Grammar:
function.call(this, arg1, arg2, ...)
Application: The child constructor inherits the properties of the parent constructor
function Father (surname) {
this.surname = surname;
}
function Son (surname) {
// Changes this in the parent constructor to this in the child constructor, and passes a value to this attribute.
Father.call(this, surname);
}
var xiaoming = new Son('xiao');
2. apply
Effect: Changes this point to call the function to pass in an argument.
Grammar:
function.apply(this, [arg1, arg2, ...])
Application: Call a method in Math
var arr = [1, 2, 3];
Math.max.apply(Math, arr);
3. bind
Effect: Change this point to pass in parameter.
Grammar:
function.bind(this, arg1, arg2, ...)
Application: Change the this pointer in setTimeout
var obj = {
data: 'first',
init: function () {
setTimeout(function(){
this.data = 'last';
}.bind(this), 3000)
}
}
obj.init();
Read More:
- Use of $watch in Vue (solve rangeerror: maximum call stack size exceeded)
- Error: Cannot find module ‘./application‘ [How to Solve]
- Vue3.0 Use el-dialog visible Error: ‘.sync‘ modifier on ‘v-bind‘ directive is deprecated. Use ‘v-model:pro
- [Solved] EurekaServerApplication: Failed to retrieve application JMX service URL
- Nuxt integrate with qiankun as the main application Error: SKIP_BECAUSE_BROKEN
- [Solved] Error in event handler for “el.form.blur“: “RangeError: Maximum call stack size exceeded“
- Vue Error: Maximum call stack size exceeded
- How to Solve Nodejs error: cannot find module ‘. /application’
- [Solved] Vue Project Modify Page Error: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory
- [Solved] uni app TypeError: undefined is not an object (evaluating ‘modules[moduleId].call‘) __ERROR
- [Solved] Vue beforeeach error: RangeError: Maximum call stack size exceeded at eval (permission.js?223d:39)
- [Solved] Vue Error: Error in nextTick: “RangeError: Maximum call stack size exceeded“
- [Solved] Vue3 Install vuetify Error: Error: You cannot call “get” on a collection with no paths.
- VUE Error: Vue Error in nextTick: “RangeError: Maximum call stack size exceeded“
- [error] IDE service port disabled. To use CLI Call, please enter y to confirm enabling CLI capabilit
- [Solved] Error: Transform failed with 1 error: error: Invalid option in transform() call: “jsx“
- How to Solve VUE Error: Avoid mutating a prop directly since the value will be overwritten …
- uniapp Use render Function Error: [Vue warn]: Error in beforeCreate hook: “TypeError: Cannot read property ‘_i‘ of
- The addition, deletion and modification of DOM in JS Foundation
- Vue refreshes the current page (no flash screen will appear)