GithubHelp home page GithubHelp logo

Comments (5)

loganfsmyth avatar loganfsmyth commented on September 26, 2024

The target of a method decorator is the class prototype, not the constructor function.

from babel-plugin-transform-decorators-legacy.

rsumilang avatar rsumilang commented on September 26, 2024

Thanks for the quick reply! What about static methods? It seems that they receive a constructor like a class instead of a prototype:

function dec(debug) {
  return (target, property, descriptor) => {
    console.log(debug);
    console.log(target);
  }
}

class A {

  @dec('from static method:')
  static doSomething(){

  }
}

Console:

from static method:
> function A () {
   _classCallback(this, A);
}

Is this intended functionality?

from babel-plugin-transform-decorators-legacy.

loganfsmyth avatar loganfsmyth commented on September 26, 2024

Yes. A method decorator's target, whether static or non-static, is the object that the property is getting added to. When you specify a non-static method, even without the decorator the method is available at Constructor.prototype.foo, with a static method it's at Constructor.foo. The decorator just gets whatever object the descriptor will be defined on.

from babel-plugin-transform-decorators-legacy.

rsumilang avatar rsumilang commented on September 26, 2024

I see (said the blind man). ;) Thanks for the explanation!

from babel-plugin-transform-decorators-legacy.

loganfsmyth avatar loganfsmyth commented on September 26, 2024

No problem, always feel free to drop by #javascript on Freenode or Babel's Slack if you have more ES6 questions.

from babel-plugin-transform-decorators-legacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.