javascript - 如何看懂api文档?
PHP中文网
PHP中文网 2017-04-11 11:03:44
[JavaScript讨论组]

有没有相关的课程可以学习,经常看api文档看的理解不对,尤其是那些缺少实例代码的。
例如下面这一段
http://docs.meteor.com/api/pubsub.html#Meteor-subscribe

Meteor.subscribe(name, [arg1, arg2...], [callbacks])
import { Meteor } from 'meteor/meteor' (ddp-client/livedata_connection.js, line 521)
Subscribe to a record set. Returns a handle that provides stop() and ready() methods.
ARGUMENTS

name String
Name of the subscription. Matches the name of the server's publish() call.
arg1, arg2... EJSON-able Object
Optional arguments passed to publisher function on server.
callbacks Function or Object
Optional. May include onStop and onReady callbacks. If there is an error, it is passed as an argument to onStop. If a function is passed instead of an object, it is interpreted as an onReady callback.


实际使用callbacks的写法应该是

Meteor.subscribe("name",{ onReady:function(){
//代码
}}

但是从文中的描述来看我根本想不到实际的写法应该是这样,不知道应该怎么理解。有没有系统的学习看api文档的教程?求教!
PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
PHP中文网

我猜你是常常对文档里出现的[]以及各种...有困惑?以你提供的文档为例:

Meteor.subscribe(name, [arg1, arg2...], [callbacks])

其实是可以看出来使用方式的,name是个必填参数(类型我们稍后讲),[arg1, arg2...]表示若干可选参数,[callbacks]表示最后一个参数是个可选的回调函数。

然后通过下面这段:

name String
Name of the subscription. Matches the name of the server's publish() call.

了解到name的类型是字符串

arg1, arg2... EJSON-able Object
Optional arguments passed to publisher function on server.

表示arg1, arg2...,这些若干可选参数,都是Object类型

诸如此类的约定,是文档界共识,看得多了,自然熟了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号