Giter VIP home page Giter VIP logo

Comments (4)

ForbesLindesay avatar ForbesLindesay commented on September 28, 2024

You don't seem to have provided the code for your entire adapter (e.g. where is executorResponseFunc defined?) so it's very difficult to know what's going on here. Ideally, provide us all the code and then maybe someone can have a quick look.

from promises-spec.

danday74 avatar danday74 commented on September 28, 2024

Hi - sorry my thinking was wrong
http://stackoverflow.com/questions/33629004/can-you-assist-me-in-satisfying-promises-aplus-spec-2-2-4-in-nodejs
Thanks for your help :)

On Tue, Nov 10, 2015 at 4:25 PM, Forbes Lindesay [email protected]
wrote:

You don't seem to have provided the code for your entire adapter (e.g.
where is executorResponseFunc defined?) so it's very difficult to know
what's going on here. Ideally, provide us all the code and then maybe
someone can have a quick look.

โ€”
Reply to this email directly or view it on GitHub
#217 (comment)
.

from promises-spec.

ForbesLindesay avatar ForbesLindesay commented on September 28, 2024

You should never return from a constructor. If you need to do inheritance (you almost certainly don't) then use extends and super rather than returning from the constructor. If you don't need inheritance (again, I'm pretty sure you don't), just use functions instead of classes. It looks like your code could simplify to just

function HTTPromise(options) {
    ... blah blah blah
    let executor = THE_REAL_EXECUTOR;
    return new Promise(executor);
}

P.S. it sounds like what you're doing is very similar to then-request which has implementations for both browser and server side. It demonstrates how to write a function that returns a promise and how to extend that promise with an extra method (.getBody).

from promises-spec.

danday74 avatar danday74 commented on September 28, 2024

thanks i appreciate your input
i know you should never return a promise from a constructor but on this
occassion we discussed it and have very valid reasons for doing so, won't
bore you with them - thanks ever so much for your help :)

On Tue, Nov 10, 2015 at 6:14 PM, Forbes Lindesay [email protected]
wrote:

You should never return from a constructor. If you need to do inheritance
(you almost certainly don't) then use extends and super rather than
returning from the constructor. If you don't need inheritance (again, I'm
pretty sure you don't), just use functions instead of classes. It looks
like your code could simplify to just

function HTTPromise(options) {
... blah blah blah
let executor = THE_REAL_EXECUTOR;
return new Promise(executor);
}

P.S. it sounds like what you're doing is very similar to then-request
https://github.com/then/then-request which has implementations for both
browser and server side. It demonstrates how to write a function that
returns a promise and how to extend that promise with an extra method (
.getBody).

โ€”
Reply to this email directly or view it on GitHub
#217 (comment)
.

from promises-spec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.