简体   繁体   English

为什么 Google Maps Map() 构造函数有副作用?

[英]Why does the Google Maps Map() constructor have side effects?

I've been working a personal Vue project that includes a simple Google map.我一直在做一个包含简单谷歌地图的个人 Vue 项目。

While implementing the Maps JS API , I annoyingly kept encountering the ESLint error 'map' is assigned a value but never used .在实现Maps JS API 时,我恼人地不断遇到 ESLint 错误'map' is assigned a value but never used assignment 'map' is assigned a value but never used I understand why I'm getting this error—The Map() constructor returns a value that I don't need to do anything with:我明白为什么我会收到这个错误——Map() 构造函数返回一个我不需要做任何事情的值:

const map = new google.maps.Map(el, options)

So I eventually just implemented the solution described in this Stack Overflow answer to bypass the lint rule.所以我最终只是实现了这个 Stack Overflow 答案中描述的解决方案来绕过 lint 规则。

If you're using a poorly designed library where the class constructor has side effects (which it isn't supposed to), and you don't need to do anything with the returned value from the class, I would disable that specific eslint rule for those lines.如果您使用的是设计不佳的库,其中类构造函数有副作用(这是不应该的),并且您不需要对类的返回值执行任何操作,我将禁用该特定的 eslint 规则对于那些行。

However, my question is, why is Google's Map() constructor designed in this way?但是,我的问题是,为什么 Google 的 Map() 构造函数是这样设计的? I have a hard time believing this library would be "poorly designed" but can't see a reason for this implementation.我很难相信这个库会“设计不佳”,但看不出这种实现的原因。

It not side effect.它没有副作用。 It's returning instance of it.它正在返回它的实例。 So you can call further methods on it所以你可以调用更多的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM