官术网_书友最值得收藏!

Callbacks

Luckily, Node creators agreed upon sane conventions on how to structure callbacks early on. It is important to follow this tradition. Deviation leads to surprises, sometimes very bad surprises, and in general, to do so automatically makes an API awkward, a characteristic other developers will rapidly tire of.

One is either returning a function result by executing a callback, handling the arguments received by a callback, or designing the signature for a callback within your API. Whichever situation is being considered, one should follow the convention relevant to that case.

The first argument returned to a callback function is any error message, preferably in the form of an error object. If no error is to be reported, this slot should contain a null value.

When passing a callback to a function, it should be assigned the last slot of the function signature. APIs should be consistently designed this way.

Any number of arguments may exist between the error and the callback slots.

To create an error object: new Error("Argument must be a String!")

主站蜘蛛池模板: 麦盖提县| 兴宁市| 昆山市| 乌恰县| 麻江县| 平度市| 若羌县| 盐津县| 康保县| 大姚县| 鄢陵县| 湟源县| 利川市| 达日县| 马尔康县| 罗江县| 鄱阳县| 中宁县| 金湖县| 祁连县| 抚远县| 台中县| 闽侯县| 南丹县| 黄大仙区| 涟源市| 东宁县| 郧西县| 塔城市| 通辽市| 湘潭县| 上林县| 曲松县| 峨边| 晋城| 论坛| 新巴尔虎左旗| 曲靖市| 龙南县| 铜梁县| 会宁县|