Skip to content

Instantly share code, notes, and snippets.

@ed-lea
Created August 12, 2015 16:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ed-lea/2b079e4319eaacda53b7 to your computer and use it in GitHub Desktop.
Save ed-lea/2b079e4319eaacda53b7 to your computer and use it in GitHub Desktop.
modify a value passed in to the extended Layer class
class Main extends Layer
constructor: (options={}) ->
# override Layer default
options.width ?= 200
# introduce the scaling factor
# Using Nexus 5 @3x by default
options.finalScale ?= 3
super options
resize: (n) ->
# returns "undefined"
print @finalScale
return n * @finalScale
@define "finalScale",
get: -> @_finalScale
set: (value) ->
@_finalScale = value
@define "width",
get: -> @_width
set: (value) ->
@_width = @resize(value)
m = new Main
# this should draw 1000 wide
width: 500
# previewing in iPhone so @2x
finalScale: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment