Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created May 8, 2013 22:31
Show Gist options
  • Save jordanorelli/5544196 to your computer and use it in GitHub Desktop.
Save jordanorelli/5544196 to your computer and use it in GitHub Desktop.
javascript APIs make me deeply sad
var picker_id = this.id + 'start-date';
this.start_date_picker = this.date_picker_container.append('input');
this.start_date_picker.attr('type', 'text');
this.start_date_picker.attr('id', picker_id);
this.start_date_picker = $('#'+picker_id).datepicker();
// this DOES NOT work:
this.start_date_picker.setDate(this.response.start_date);
// instead, you have to do this:
$('#'+picker_id).datepicker('setDate', this.response.start_date);
@jordanorelli
Copy link
Author

you're right; it's totally hyperbolic. If I've learned anything about commenting on programming, it's that constructive dialogue that isn't completely hyperbolic doesn't get people to pay attention and click on your links.

yep, I'm using requirejs. It's... decently helpful. I'm not so sure my mind is blown but I've found it to be helpful for my project, so I see why people use it. You have to shim jquery-ui but it's not a big deal. It doesn't really clean up this particular problem though.

Anyway, we have some module, and it adds this datepicker method to the jQuery object (in your example you don't actually call datepicker but I'm guessing it's just a typo and doesn't merit discussion). All my gripe is that when you run datepicker(), it should return an object that has appropriate methods on it. You'd still only be adding a single method, datepicker, to the jquery object; it's the return value that would get the setDate method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment