gpt4 book ai didi

javascript - 为什么自定义传单控件添加为大写和小写?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:10:51 25 4
gpt4 key购买 nike

我正在查看扩展传单文档以添加 custom controls .

它包含此代码片段作为添加简单水印控件的示例:

L.Control.Watermark = L.Control.extend({
onAdd: function(map) {
var img = L.DomUtil.create('img');

img.src = '../../docs/images/logo.png';
img.style.width = '200px';

return img;
},

onRemove: function(map) {
// Nothing to do here
}
});

L.control.watermark = function(opts) {
return new L.Control.Watermark(opts);
}

L.control.watermark({ position: 'bottomleft' }).addTo(map);

为什么将控件分配给大写 (L.Control.Watermark) 和小写 L.control.watermark 变量?这是扩展 JavaScript 库时的常见约定吗?

最佳答案

如果您查看名为 Extending Leaflet: Class Theory 的教程,您会看到一个名为 Factories 的部分:

Most Leaflet classes have a corresponding factory function. A factory function has the same name as the class, but in lowerCamelCase instead of UpperCamelCase.

基本上,lowerCamelCase 函数是实例化相应类的便捷方法。您会找到很多关于为什么使用工厂函数而不是构造函数的文章,this one看起来很全面

关于javascript - 为什么自定义传单控件添加为大写和小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51657310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com