Git Product home page Git Product logo

Comments (4)

taylorhakes avatar taylorhakes commented on September 21, 2024

You are able to do this if you are using import or require.

import Promise from 'promise-polyfill';

window.Promise = Promise;

Does that work?

from promise-polyfill.

Diniden avatar Diniden commented on September 21, 2024

This does not work if the polyfill is externally bundled as its own bundle.

So the scenario for this build system: it takes in third party libraries and bundles them into standalone bundles.

Then modules requiring the third party libraries get them loaded in via AMD.

It's difficult to single out libraries for non bundling as that generates too many special cases in the procedure.

from promise-polyfill.

taylorhakes avatar taylorhakes commented on September 21, 2024

@Diniden I am confused how you want the library to work. You said you wanted to do this

import polyfill from 'promise-polyfill';
polyfill(window);

I gave you that ability

import Promise from 'promise-polyfill';
window.Promise = Promise;

You can even create the polyfill function

import Promise from 'promise-polyfill';
function polyfill(globalObj) {
  globalObj.Promise = Promise;
}
polyfill(window)

I feel like you want the library to do something that is not possible with Javascript. There is no way to magically return a module without attaching to this, using module.exports or using define. Do you just want define? You mentioned you are using AMD.

If you could tell me how to change this library's code to make it work for you, that would be really helpful.

from promise-polyfill.

Diniden avatar Diniden commented on September 21, 2024

It seems I am a bit of a dummy. Yes:

import Promise from 'promise-polyfill';
window.Promise = Promise;

Works for me :)

Me being a dummy though, I gave my question a lot of un-needed thought and came up with a solution I thought I needed:

var promisePolyfill = (function polyfill(root) {
  // The code....
  return polyfill;
})(this);

// I could now:
promisePolyfill(myOwnContext);

But that being said....I don't really need that...You may close this and hide my shame now :) thanks for your time regarding this!

from promise-polyfill.

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.