wrong this in lib #33

Closed
opened 2019-05-04 19:38:37 +00:00 by lewismoten · 1 comment
lewismoten commented 2019-05-04 19:38:37 +00:00 (Migrated from github.com)

Using v0.1.0 - calling reader.readFromat() throws an error. Looking at generated code, functional wrappers are redefining this

Test

const RiffReader = require("riff-wave-reader").Reader;

const file = path.join(__dirname, "hello.wav");
const reader = new RiffReader(file);
reader
  .readRiff()
  .then(reader.readFormat)
  .then(reader.readDataHeader)
  .then(() => {
    // readSample(channel, index) {
    console.log("GOT IT");
  })
  .catch(e => console.log("ERROR", e));

Error

ERROR TypeError: Cannot read property 'format' of undefined
    at C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\read-format-header.js:17:17
    at new Promise (<anonymous>)
    at readFormatHeader (C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\read-format-header.js:16:10)
    at readFormat (C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\index.js:35:53)

v0.1.1 code source

_createClass(Reader, [{
    key: "readRiff",
    value: function readRiff() {
      return (0, _readRiffHeader.readRiffHeader)(this);
    }
  }, {
    key: "readFormat",
    value: function readFormat() {
      return (0, _readFormatHeader.readFormatHeader)(this);
    }
  }, {
Using v0.1.0 - calling `reader.readFromat()` throws an error. Looking at generated code, functional wrappers are redefining `this` # Test ```js const RiffReader = require("riff-wave-reader").Reader; const file = path.join(__dirname, "hello.wav"); const reader = new RiffReader(file); reader .readRiff() .then(reader.readFormat) .then(reader.readDataHeader) .then(() => { // readSample(channel, index) { console.log("GOT IT"); }) .catch(e => console.log("ERROR", e)); ``` # Error ```bash ERROR TypeError: Cannot read property 'format' of undefined at C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\read-format-header.js:17:17 at new Promise (<anonymous>) at readFormatHeader (C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\read-format-header.js:16:10) at readFormat (C:\dev\cute-piano-odyssey\node_modules\riff-wave-reader\lib\index.js:35:53) ``` # v0.1.1 code source ``` _createClass(Reader, [{ key: "readRiff", value: function readRiff() { return (0, _readRiffHeader.readRiffHeader)(this); } }, { key: "readFormat", value: function readFormat() { return (0, _readFormatHeader.readFormatHeader)(this); } }, { ```
lewismoten commented 2019-05-04 20:11:33 +00:00 (Migrated from github.com)

This is a non-issue. Passing in the method name via .then(reader.readFormat) is redefining the context of this. Fix is to call .then(() => reader.readFormat.then(() =>

This is a non-issue. Passing in the method name via `.then(reader.readFormat)` is redefining the context of `this`. Fix is to call `.then(() => reader.readFormat.then(() =>`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lewismoten/riff-wave-reader#33
No description provided.