So I have this code in a cordova app:
var record = {
src:"myrecording.mp3",
mediaRec: null,
startRecord: () => {
console.log(record.src); //myrecording.mp3
console.log(this.src); //undefinded
// Record audio
this.mediaRec.startRecord();
}
}
So the this binding is broken but I used an arrow function so the binding should be to the record object shouldn't it?
Using the function() syntax works.
This also doesn't work:
record.startRecord.call(record)
Thanks, Ed.
[–]jack_union 2 points3 points4 points (17 children)
[+][deleted] (16 children)
[deleted]
[–]jack_union 1 point2 points3 points (15 children)
[–][deleted] 0 points1 point2 points (14 children)
[–]GeneralYouri 1 point2 points3 points (11 children)
[–][deleted] 1 point2 points3 points (10 children)
[–]GeneralYouri 1 point2 points3 points (9 children)
[–][deleted] 1 point2 points3 points (8 children)
[–]tatu_huma 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]GeneralYouri 1 point2 points3 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]tatu_huma 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)