我真的很困惑,我应该如何记录这三种方法(onKick,offKick,triggerKick):
var events = $( {} ); // jQuery Pub/Sub .
/**
* Creates a football player .
* @constructor
*/
function Player() {
...
}
Player.prototype = {
...,
/**
* Subscribes a function to the kick event .
* @param {Function} fn An event handler .
*/
onKick: function( fn ) {
events.on('kick.FootballGame', fn);
},
/**
* Unsubscribes a function from the kick event .
* @param {Function} fn The event handler .
*/
offKick: function( fn ) {
events.off('kick.FootballGame', fn);
},
/**
* Kicks the ball .
* @fires kick.FootballGame
*/
triggerKick: function() {
events.trigger('kick.FootballGame');
},
...
};
谢谢。
答案 0 :(得分:0)
我说你接近一个记录良好的脚本块。我会提出一些更改,在您的代码中说明:
/**
* Creates an new Football Player.
* @constructor
*/
function Player() {
...
}
Player.prototype = {
/**
* Subscribes a function to the kick event.
* @param {function} fn - an event handler.
*/
onKick: function( fn ) {
events.on('kick.FootballGame', fn);
},
...
};
一般规则:
{function}
而不是{Function}