Call Method (Function) (JavaScript)

Source: Internet
Author: User

Call Method (Function) (JavaScript)invokes the method of an object, replacing the current object with another object. Grammar
Call ([thisobj[, arg1[, arg2[,  [, ArgN]]])
 parameter  
 

thisobj

optional.

arg1, arg2, ArgN

Optional. The argument list that will be passed to the method

Note

call The   method is used to invoke a method that represents another project. It allows you to change the function  this   object from the initial context to the  thisobj   new object specified.

If the thisobj parameter is not provided, the global object is used as the thisobj.

The following code demonstratesPagerMethod
 

function Add (A, B)

{Console.info (this);Console.info (A+B);  } function sub (a, b) {console.info (a); }

Call

Add.call (sub,3,1);

Result output

Call

Add.call (' "HH" ', 3,1);

Add.call (3,1);

The second paragraph of the procedure

function Animal () {

THIS.name = "Animal"; This.showname = function () {Console.info (this);Console.info (this.name);    }} function Cat () {this.name = "cat";    } var animal = new animal ();         var cat = new Cat ();    Animal.showName.call (Cat, ",");   Animal.showName.call (CAT); Animal.showName.call ();

Third paragraph procedure

function Animal (name) {

THIS.name = name;        This.showname = function () {console.info (' call ', this);          Console.info (this.name);    }} function Cat (name) {Console.info ("init", this);    Animal.call (this, name);     } var cat = new Cat ("Black cat");  Cat.showname (); Console.info (Cat.showname);

Call Method (Function) (JavaScript)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.