Skip to content

Package definitions #2087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Package definitions #2087

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 1, 2012

Hi, Jeremy! I wrote some code on my work. All code was for the browsers and I need to protect classes by packing them into packages. My preparsers was dirty with regexps, but now I decide to make it right and I want to suggest using packages as standart coffeescript tool. By the way thx a lot for coffee, it awesome!

Usage example, this code creates class cafe.dom.Window:

  package "cafe.dom"

    class Window

      @getViewPortSize: () ->
        myWidth = 0
        myHeight = 0

        if typeof window.innerWidth is 'number'
          #Non-IE
          myWidth  = window.innerWidth
          myHeight = window.innerHeight
        else if (doc = document.documentElement) and (doc.clientWidth or doc.clientHeight)
          #IE 6+ in 'standards compliant mode'
          myWidth  = doc.clientWidth
          myHeight = doc.clientHeight
          doc = null
        else if (body = document.body) and (body.clientWidth or body.clientHeight)
          #IE 4 compatible
          myWidth  = body.clientWidth
          myHeight = body.clientHeight

        return {
          width : myWidth
          height: myHeight
        }

@michaelficarra
Copy link
Collaborator

See #1141, #684. We don't need a special syntax for this.

@ghost
Copy link
Author

ghost commented Feb 2, 2012

Why not, I can't understand. Keyword package is reserved in JS and it means to create packages. Yes, it's not very useful for server side dev, but in the browsers it helps to safe classes from override. Each time write something like this:

  @cafe or= {}
  cafe.dom or= {}

  cafe.dom.Window = class Window

it's not cool and not compact. You couldn't understand what is it at the first look. But if you look at this:

  package "cafe.dom"
    class Window

all clear! Believe me it wouldn't be a special function, it's like shortcut, like class keyword for example.

@michaelficarra
Copy link
Collaborator

#1141 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants