Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Last active December 17, 2015 18:19
Show Gist options
  • Select an option

  • Save ELLIOTTCABLE/5652573 to your computer and use it in GitHub Desktop.

Select an option

Save ELLIOTTCABLE/5652573 to your computer and use it in GitHub Desktop.
# `construct()` comes from:
# https://github.com/elliottcable/Paws.js/blob/84c75de3ec6f829501bfdc9d0d6e472b31ed7d9a/Source/utilities.coffee#L39-L47
Label: class Label extends Thing
constructor: (string) ->
it = construct this
super.apply(it)
it.alien = new String string
it.alien.native = this
return it
@ELLIOTTCABLE
Copy link
Author

Of note:

  • The construct() approach taken here is about to be replaced with a bit more “magic” metaprogrammatic approach, with a higher-level function (constructify()?) that automatically wraps our constructor such that it operates the same way we've got it working here with an explicit construct()
  • Boxing string for a performance enhancement elsewhere
  • having to return it, as CoffeeScript doesn't treat constructors the way it treats everything else (understandably.) when it comes to return values; without an explicit return, which CoffeeScript won't automatically provide here, JavaScript returns the original this of the function, which we're changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment