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

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!")

主站蜘蛛池模板: 汉川市| 朝阳区| 来安县| 古交市| 会宁县| 田阳县| 东阿县| 讷河市| 霍州市| 莫力| 隆尧县| 东乡族自治县| 贺兰县| 高州市| 达拉特旗| 西乡县| 文成县| 白朗县| 沭阳县| 金堂县| 朔州市| 邵阳县| 汽车| 通化县| 伊川县| 北流市| 定边县| 文山县| 东丽区| 当雄县| 大埔区| 定兴县| 通山县| 黄平县| 两当县| 嫩江县| 公主岭市| 南昌市| 华安县| 登封市| 广丰县|