Return class from class method

18 views
Skip to first unread message

Herman Bergwerf

unread,
Jul 26, 2016, 5:03:37 AM7/26/16
to Skulpt
I need to return a class B from the method from another class (say `A.getB()`) It will also be wrapped in a promise but that won't matter here (I think). I have something like this:

```
return {
  type: Sk.promise,
  promise: new Promise(function (resolve, reject) {
    fetch(url, {
      method: self.method,
      mode: 'cors',
      cache: 'default'
    }).then(function (response) {
      self.response = response
      resolve(...stuff goes here...)
    }).catch(function (err) {
      throw new Sk.builtin.IOError(err.message)
    })
  })
}
```

How should I do this?

Thanks!
Herman

Brad Miller

unread,
Jul 26, 2016, 1:42:41 PM7/26/16
to sku...@googlegroups.com
Hi,

If you look at the source for the image module you will see an example of what I think you are trying to do.

The image object has a getPixel method which returns an instance of the Pixel class.

Brad

Bradley Miller, PhD
Professor, Dept. Chair, Computer Science
Luther College
Founder, Runestone Interactive
Blog: A Reputable Journal

--

---
You received this message because you are subscribed to the Google Groups "Skulpt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages