简体   繁体   English

Javascript类库处于关闭状态

[英]Javascript class library in closure

I'm attempting to create a JS class library in a closure for a Drupal application (the Drupal thing is not necessarily relevant but style insists on closures). 我试图在一个Drupal应用程序的闭包中创建JS类库(Drupal的东西不一定相关,但是样式坚持闭包)。 I'm not a coding newbie but JS is not my area of expertise :-) 我不是编码新手,但JS不是我的专长:-)

The first problem I have is that the "extends" doesn't work - I understand that I don't have the right reference for the extends class, but what should it be, because I can't find anything that works? 我的第一个问题是“扩展”不起作用-我知道我没有对extends类的正确引用,但是应该是什么,因为找不到任何有效的东西?

 ((window) => { window.lib = { LibClassBase: class {} LibClass1: class extends LibClassBase {} } })(window) 

Alternatively: is this just the wrong approach and should I be doing something else? 或者:这只是错误的方法,我还应该做其他事情吗?

is this just the wrong approach 这是错误的方法吗

Yes. 是。

You can't read a value from an object before it has been constructed. 在构造对象之前,您无法从对象中读取值。

and should I be doing something else? 我应该做别的事情吗?

Use class declarations and create them within the scope of the closure. 使用类声明并在闭包范围内创建它们。

Assign them to the object you are returning afterwards. 将它们分配给之后要返回的对象。

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

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