stampit-org / stamp-specification

The Stamp Specification: Composables
434 stars 16 forks source link

when use compose, got 'xx.xx is not a function' #124

Closed lornally closed 5 years ago

lornally commented 5 years ago
import stampit from './compose.js';

const yy = stampit().compose({
    props: {
      i: 'iiiii',
    },
    methods: {
      get info() {
        return `get${this.i}`;
      },
      set info(info) {
        this.i += `hahah${info}`;
      },
      pp() {
        this.i += 'p';
        return this.i;
      },
    },
  });

  log('object pp:', yy.pp()); //here, get the bug: yy.pp is not a function

  log('object pp:', yy.pp());

at first, this is not right too:


const zz = stampit().compose({
    i: 'iiiii',
    get info() {
      return `get${this.i}`;
    },
    set info(info) {
      this.i += `hahah${info}`;
    },
    pp() {
      this.i += 'p';
      return this.i;
    },
  });
koresar commented 5 years ago

That's the same problem. Getters and setters are not supported.

lornally commented 5 years ago

no ,it is not same problem, although i use this simple code:

const yy = stampit().compose({
    props: {
      i: 'iiiii',
    },
    methods: {
      pp() {
        this.i += 'p';
        return this.i;
      },
    },
  });
  log('object pp:', yy.pp()); //here, get the bug: yy.pp is not a function
  log('object pp:', yy.pp());
  const zz = stampit().compose({
    i: 'iiiii',
    pp() {
      this.i += 'p';
      return this.i;
    },
  });
log('object pp:', zz.pp()); //here, get the bug: yy.pp is not a function
koresar commented 5 years ago

Oh. I see. Stampit has more API than the compose function. https://stampit.js.org/essentials/what-is-a-stamp

In your case the "props" is not recognised by compose function.

lornally commented 5 years ago

thanks, that my mistake, yy is a stamp, not a object, if i want a object, i need stamp it .:) here is the right code:

 const yy = stampit().compose({
    properties: {
      i: 'iiiii',
    },
    methods: {
      pp() {
        this.i += 'p';
        return this.i;
      },
    },
  });
  const yyy=yy();
  log('object pp:', yyy.pp());
  log('object pp:', yyy.pp());