Giter VIP home page Giter VIP logo

Comments (2)

jmdobry avatar jmdobry commented on May 31, 2024

The methods option is just a plain object, whose keys are names and values are functions. When the resource is defined, methods is mixed into the prototype of the instance constructor function that will be used by the new resource when it creates instances. ES6 classes put the methods onto the prototype as well. Since you want to write in ES6, I'm thinking you need to define your classes first and then mix the resulting prototype methods into the methods object. You probably don't want to blindly pull everything from the class prototype, but pick the ones you want.

Something like this:

class Foo {
  constructor() {
    this.foo = 'bar';
  }
  baz() {
  }
  boo() {
    console.log(this.foo);
  }
}
var foo = new Foo();
foo.boo(); // "bar"

var Bar = DS.defineResource({
  name: 'Bar',
  methods: DS.utils.pick(Foo.prototype, ['baz', 'boo'])
});

var bar = Bar.createInstance({
  foo: 'baz'
});

bar.boo(); // "baz"

Let me know how it works out for you.


Closing because Iā€™m not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:

  • good - Your versions of JSData, etc, relevant console logs/error, code examples that revealed the issue
  • better - A plnkr, fiddle, or bin that demonstrates the issue
  • best - A Pull Request that fixes the issue, including test coverage for the issue and the fix

Otherwise support is done via the mailing list.

from js-data.

pietschy avatar pietschy commented on May 31, 2024

Excellent, I'll give that a go. Thanks.

from js-data.

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.