Skip to content
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

assigning attributes to self #795

Open
madmaniak opened this issue Jan 23, 2023 · 4 comments
Open

assigning attributes to self #795

madmaniak opened this issue Jan 23, 2023 · 4 comments

Comments

@madmaniak
Copy link
Member

Description

There's neat syntax in Coffeescript:

class Dog
  constructor: (@name) ->

# is equal to:

class Dog
  constructor: (name) ->
    this.name = name

And I miss it here even Imba was forked from Coffeescript years ago.
It could be @ or $ prefix or ! postfix to tell that argument should be assigned to self.

Why

It is repeatable in any object oriented program. I mean assigning attributes to the object
without any modification.

Is this something you're interested in working on?

Yes

@familyfriendlymikey
Copy link
Member

This isn't exactly what you're describing, but it might be to your liking:

class Note
	name = 'hello'

let note = new Note(name:'world')

console.log note

@madmaniak
Copy link
Member Author

I receive Note object with property name: 'world'. Previous name 'hello' declaration is class attribute or default object value?

@familyfriendlymikey
Copy link
Member

'hello' is the default value. I'm showing that you can pass in custom values by supplying an object as the argument, in this case we're creating a Note and setting name to 'world'.

@madmaniak
Copy link
Member Author

OK this is constructor only, right?

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

No branches or pull requests

2 participants