Skip to content

Comment on Designing Javascript APIs

Comments

Thanks for sharing. Something you touched on but didn't explicitly stated is to have a standard and uniform interface everywhere.

My go-to example would be JQuery.. It feels like once you understand $('a.test').click(function() {..});, you understand and, most importantly, feel how everything else behave.

For instance, what if I don't want a click but a mouse hover? I don't have to read the doc or google.. I can just try .hover() and 9 times out of 10 it will work.

A bad API forces you to spend hours reading the doc because the 10 most obvious tries failed. Most of the time, these ugly APIs come also with bad or lack of documentation and backward-breaking changes without notifications. Yes, I'm talking about Facebook' API.

Agreed, its a pleasure working with jQuery because 1. things are consistent & complete , so its very easy to guess what a function should be named and how it would work, and 2. the docs are great. every function has an easy small description and some good examples.

2. also reflects how well chaining works.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.