Skip to content

Instantly share code, notes, and snippets.

@yuanchuan
Created August 18, 2011 01:25
Show Gist options
  • Save yuanchuan/1153080 to your computer and use it in GitHub Desktop.
Save yuanchuan/1153080 to your computer and use it in GitHub Desktop.
hacking
var message = (function() {
var _buf = ['hello', 'hi']
, _len = _buf.length
, M = Math;
return {
get: function(){
return _buf[M.floor(M.random() * _len)] || '';
}
, add: function() {
_buf.push.apply(_buf, arguments);
_len = _buf.length;
}
, _print: function() {
if ( window.console ) {
console.log.apply(console, _buf);
} else {
alert(_buf.join(' '));
}
}
, _clear: function() {
_len = _buf.length = 0;
}
};
}());
var sendMsg = (function() {
var _occr = 1
, _times = window.times = function(n, callback) {
while (n--) callback();
}
, _sendTo = function(user, msg) {
window.net && net.send_message(
0x0002,
"<c><c>chat</c><ch>"+2+"</ch><to>"+user+"</to><text>"+msg+"</text></c>"
);
};
return function(msg) {
return {
times: function(num) {
_occr = (typeof num === 'number') ? num : 1;
return this;
}
, to: function(user) {
_times(_occr, function(){
_sendTo(user, msg);
});
_occr = 1;
return this;
}
};
};
}());
//hacking
sendMsg('hello im a bomber').to('user');
times(10, function() {
sendMsg( message.get() ).to('user');
});
sendMsg( message.get() )
.times(10).to('me')
.times(20).to('you');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment