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

Can we use a class constructor as a decorator? #1218

Closed
okunokentaro opened this issue Apr 10, 2015 · 2 comments
Closed

Can we use a class constructor as a decorator? #1218

okunokentaro opened this issue Apr 10, 2015 · 2 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@okunokentaro
Copy link

In angular2.

https://github.com/angular/angular/blob/master/modules/angular2/src/core/annotations/annotations.js#L482

Component is defined as a class. In my code app.es6 in the following, the Component constructor is used as a decorator.

import {Component, Template, bootstrap} from 'angular2/angular2';
import {Greeter} from './greeter';

@Component({              // <-- here
  selector: 'hello-app',
  services: [Greeter]
})
@Template({
  inline: `
    <p>{{message}}</p>
  `
})
class HelloApp {
  constructor(greeter) {
    this.message = greeter.hello('Angular 2 app');
  }
}

bootstrap(HelloApp);

However, runtime throws Uncaught TypeError: Cannot call a class as a function in _classCallCheck()

var Component = (function (_Directive) {
  function Component() {
    var _ref2 = arguments[0] === undefined ? {} : arguments[0];

    var selector = _ref2.selector;
    var bind = _ref2.bind;
    var events = _ref2.events;
    var services = _ref2.services;
    var lifecycle = _ref2.lifecycle;

    _classCallCheck(this, Component); // <-- maybe is this the cause?

    _get(Object.getPrototypeOf(Component.prototype), 'constructor', this).call(this, {
      selector: selector,
      bind: bind,
      events: events,
      lifecycle: lifecycle
    });
    this.services = services;
  }

  _inherits(Component, _Directive);

  return Component;
})(Directive);

Is it correct that we use a class constructor as a decorator?
Thanks.

@sebmck
Copy link
Contributor

sebmck commented Apr 10, 2015

You can only new classes so you can't call them which includes calling them as a decorator. Thanks!

@sebmck sebmck closed this as completed Apr 10, 2015
@okunokentaro
Copy link
Author

I see, thank you master!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 22, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants