为什么将自定义传单控件添加为大写和小写? [英] Why are custom leaflet controls added as upper and lower case?

查看:88
本文介绍了为什么将自定义传单控件添加为大写和小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看扩展传单文档,以添加自定义控件.

I am looking at the Extending Leaflet documentation for adding custom controls.

其中包含以下代码段,作为添加简单水印控件的示例:

It contains this code snippet as an example of adding a simple watermark control:

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库时,这是常见的约定吗?

Why is the control assigned to both uppercase (L.Control.Watermark) and lowercase L.control.watermark variables? Is this a common convention when extending JavaScript libraries?

推荐答案

如果您查看名为扩展传单:类理论,您会看到名为工厂:

If you look at the tutorial named Extending Leaflet: Class Theory, you'll see a section named Factories:

大多数Leaflet类具有相应的工厂功能.工厂函数与该类具有相同的名称,但是在 lowerCamelCase 中而不是在 UpperCamelCase 中.

基本上, lowerCamelCase 函数是实例化相应类的一种便捷方法.您会发现很多文章,为什么要在构造函数上使用工厂函数,这个似乎很全面

Basically, the lowerCamelCase function is a convenience method to instantiate the corresponding class. You'll find plenty of articles on why use factory functions over constructors, this one seems quite comprehensive

这篇关于为什么将自定义传单控件添加为大写和小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆