en.javascript.info/02-ui/05-widgets/02-widgets-structure/05-voter-proto/solution/voter.js
Ilya Kantor f301cb744d init
2014-10-26 22:10:13 +03:00

22 lines
543 B
JavaScript
Executable file

function Voter(options) {
var elem = this._elem = options.elem;
this._voteElem = elem.find('.vote');
elem.on('mousedown selectstart', false);
elem.on('click', '.down', this._onDownClick.bind(this));
elem.on('click', '.up', this._onUpClick.bind(this));
}
Voter.prototype._onDownClick = function() {
this._voteElem.html( +this._voteElem.html() - 1 );
};
Voter.prototype._onUpClick = function() {
this._voteElem.html( +this._voteElem.html() + 1 );
};
Voter.prototype.setVote = function(vote) {
this._voteElem.html(vote);
};