medikoo / deferred

Modular and fast Promises implementation for JavaScript
ISC License
364 stars 20 forks source link

get extension method, handling errors #4

Closed alexbft closed 12 years ago

alexbft commented 12 years ago

Sample code:

var deferred = require('deferred');
deferred(null).get('a').then(console.log, function() { console.log('an error happened'); });

Currently it throws an exception (TypeError: Cannot read property 'a' of null). I think it should fail the promise instead. This case applies to the invoke method as well.

medikoo commented 12 years ago

@alexbft on which version of deferred you're working?

Latest deferred works as expected:

$ node
> var deferred = require('deferred');
undefined
> deferred(null).get('a').then(console.log, function() { console.log('an error happened'); });
an error happened

Maybe some older version have such logic error. Let me know.

medikoo commented 12 years ago

I've looked into history, it was fixed with 0.5.0. If you're not sure about switching from 0.4 to 0,5 check CHANGES document for all changes information (it however missed information about that fix, I've added it now)

alexbft commented 12 years ago

Yeah, it was version 0.4.3. Thanks!

medikoo commented 12 years ago

You're welcome.

I've just found that we still had similar issue with invoke extension (for null or undefined context). I've fixed it and updated deferred to v0.5.1 version