I’m new to CoffeeScript, and I like the CoffeeScript classes, but can’t work out how to extend them in jQuery using jQuery.prototype.
This is for part of my app that holds sort-of global state variables, so I want to call it via $.myThing.myFunction(), and not the usual $.fn.extend / $().myThing() extending way.
I can get it to work like this:
$ = jQuery
$.myThing = $.myThing || {}
$.extend $.myThing, {
myProperty: 0
myFunction: ->
}
Which is okay, but then I can’t use it as a class, and the structure doesn’t look pretty my pycharm. (Which, being honest is probably bothering more than the whole class thing…)
What I want, is to do something like this:
$ = jQuery
$.myThing = $.myThing || {}
class myThing
myProperty: 0
myFunction: ->
$.extend $.myThing, myThing()
But it doesn’t work (other than looking pretty in pycharm). Is there a better way to do this?
Would this work for you?
Compiles to:
Edit:
$.myThingas an instance of the class: