For context, that answer (and question) is from 2009 and viewed over 150K times.
So up until revision 3 this was the start of the answer:
The solution is the binding of variables through closure.
I haven't used the .post function in jQuery, but a quick scan of the documentation suggests the call back should be a function pointer accepting the following:
function callBack(data, textStatus, jqXHR) {};
Therefore I think the solution is as follows:
var doSomething = function(extraStuff) {
return function(data, textStatus, jqXHR) {
// do something with extraStuff
};
};
var clicked = function() {
var extraStuff = {
myParam1: 'foo',
myParam2: 'bar'
}; // an object / whatever extra params you wish to pass.
$.post("someurl.php", someData, doSomething(extraStuff), "json");
};
In revision 4 all that was added was a generalized basic example:
As a more basic example, here is an example function that receives and calls a callback function, as well as an example callback function:
function callbackReceiver(callback) {
callback("Hello World");
}
function callback(value1, value2) {
console.log(value1, value2);
}
This calls the callback and supplies a single argument. Now you want to supply an additional argument, so you wrap the callback in closure.
callbackReceiver(callback); // "Hello World", undefined
callbackReceiver(function(value) {
callback(value, "Foo Bar"); // "Hello World", "Foo Bar"
});
I honestly don't see why that would be a bad edit, why it would be in conflict with the intent of the author or why it would be an attempt to reply to the author. That edit simply captures what the OP stated in their own words. The edit makes the answer better and wider applicable.
On top of that the editor left an extended comment, explaining their edit, so both the OP and any visitors would notice what has been done.
In our arsenal of moderation options editing is one of them. It seems like, based on the other answers, we're restricted to some grammar fixes, layout or rewording and I guess salvaging utter crap. That is a bit too restrictive, IMHO. I don't see why you couldn't and why we shouldn't edit a great answer into more greatness. That it is not your own post, who cares? Stuff gets better! Be happy!
All we have to do is judge the edit and the post on its merit. In this case I think it makes the post better and with that this small part of the internet.