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);
@JoeM05
Copy link

JoeM05 commented May 9, 2013

it's not that hyperbolic a statement - the "community" (if you want to call it that) is not focused on the craft (like the Python community for example) but on creating useable and reusable code usually with production in mind. Since Javascript was written in something like a month by a guy (forgot his name) working at Netscape in an attempt to sail the next cannonball in the ie netscape browser wars - it doesn't have the Guido or the Matz shepherding its development and fostering its community.
Instead it's development is handled by a comity.
I'm sure a lot of this refusal to come up with simplified conventions that you've noticed comes from that fact that it was sort of an orphaned bastard child.

@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