用户脚本中规则的排列顺序是否会产生实际差异?
用户脚本头部元数据顺序的影响说明
- 两种排列方式没有功能上的区别,顺序调整完全属于个人偏好或社区惯例差异,不会影响脚本的正常运行。
- 脚本管理器(比如Tampermonkey、Greasemonkey)识别头部元数据时,是根据
@name、@namespace这类标签的关键字来解析内容,而不是依赖它们的排列顺序。 - 常见的惯例是把
@namespace和@name放在最前面,因为这两个标签组合起来是脚本的唯一标识(用来区分不同脚本),但反过来排列也不会有任何问题。
第一种排列:
// @name Hello, name here! // @author Author is here! // @description Description is here! // @namespace Namespace is here!
第二种排列:
// @namespace Namespace is here! // @author Author is here! // @description Description is here! // @name Hello, name here!
内容的提问来源于stack exchange,提问作者Kevin Mahrous
相关产品推荐
相关产品推荐

