Home > Web Front-end > JS Tutorial > Chained calls in javascript_javascript skills

Chained calls in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:34:31
Original
1205 people have browsed it

The way in jQuery looks like $("#txtName").addClass("err").css("font-size","12px").select().focus(); makes people fascinated by it. The implementation mechanism is chain call. Chain calling is to call the method of an object and then return to the object. Strictly speaking, it does not belong to grammar, but is just a grammar technique. This is the fascinating point of js.
Methods without return values ​​are assignor methods. Obviously, it is easy to implement chain calls, provided that the usage of this pointer is correctly understood.

Copy code The code is as follows:

function W(){
this.name= "Wang Hongjian";
this.gender="male";
}
W.prototype.sayHi=function(){
alert("Hello,everybodynMy name is " this.name);
return this;
};
W.prototype.doSomething=function(){
alert("I'm working");
return this;
}
W.prototype.sayGoodbye=function(){
alert("Goodbye,everybody");
return this;
};
var w=new W();
w.sayHi ().doSomething().sayGoodbye();


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
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