1.this
In general, in JavaScript, this points to the current object when the function executes .
2.new
In JavaScript, after using the new keyword, it means doing the following four things:
- Creates a new object, the type of which is Object ;
- Set the internal, accessibility, and [[prototype]] properties of this new object to be set in the constructor (referred to as the constructor pointed to by Prototype.construtor);
- Executes the constructor when the This keyword is mentioned, using the properties of the newly created object;
- Returns the newly created object (unless ' No prototype ' is returned in the constructor method).
3.delete
The delete operator is often used to delete an object's properties, rather than a generic variable or function.
4.call
Apply to: Function Object
Invokes one method of an object, replacing the current object with another object.
Call ([thisobj[,arg1[, arg2[, [,. ArgN]]])
Parameters:
Thisobj
Options are available. The object that will be used as the current object.
Arg1, Arg2,, ArgN
Options are available. The method parameter sequence will be passed.
Description
The call method can be used to invoke a method in place of another object. The call method can change the object context of a function from the initial context to a new object specified by Thisobj. If the Thisobj parameter is not provided, then the Global object is used as the thisobj.
5.apply
Call, Apply is a method of Function.prototype, which is implemented internally by the JavaScript engine because it belongs to Function.prototype, so each function object instance, that is, each method has a call , apply property. As a property of the method, the use of them is of course a method. These two methods are easy to confuse, because they work the same way, but only in different ways.
Function.apply (Obj,args) method can receive two parameters
OBJ: This object will replace the This object in the function class
Args: This is an array, which is passed as a parameter to function (args-->arguments)
6. Run and debug the JS code to help understand the above concepts.
7. Use call to implement class inheritance. The code is called "Base.call (This)" in the constructor of Class B, and B can use the methods and properties in Base.
function B () { base.call (this); this.name = ' B '; This.age = 2; } var B = new B (); B.show ();
JavaScript this,new,delete,call,apply (RPM)