• Notice regarding image hosts and attachments. See here.

Refactoring JavaScript help

Soldato
Joined
27 Oct 2006
Posts
8,047
Location
London
OK I'm no JS coder but yay or nay to this || which version do you prefer ?....

Original code
Code:
function myupdatebart2(){
	if ($('.on_off :checkbox').prop('checked') == false) {
		socket.emit('updatebart2', false);
	} else {
		socket.emit('updatebart2', true);
	}
};
$('.on_off :checkbox').iphoneStyle({ onChange : myupdatebart2 });

Revision 2 - No point to this ? {works}

$('.on_off :checkbox').iphoneStyle({ onChange : function () { $('.on_off :checkbox').prop('checked') == false ? socket.emit('updatebart2', false) : socket.emit('updatebart2', true);} });

Revision 3 - Probably the best candidate {works}

$('.on_off :checkbox').iphoneStyle({ onChange : function () { socket.emit('updatebart2', $('.on_off :checkbox').prop('checked'));} });

Revision 4 - Makes obvious sense but the param needs a reference to a function and hence fails {fail}

$('.on_off :checkbox').iphoneStyle({ onChange : socket.emit('updatebart2', $('.on_off :checkbox').prop('checked')) });
 
Back
Top Bottom