Giter Club home page Giter Club logo

Comments (6)

nickdesaulniers avatar nickdesaulniers commented on May 24, 2024

so I would imagine then I could do:

var events = [
  'negotiationneeded',
  'icecandidate',
  'icecandidateerror',
  'signalingstatechange',
  'iceconnectionstatechange',
  'icegatheringstatechange',
  'connectionstatechange'
];
RTCPeerConnection.prototype = new EventTarget(events);

from event-target-shim.

mysticatea avatar mysticatea commented on May 24, 2024

Thank you for the issue.

OK, it sounds reasonable.
I will do it this evening (JST).

from event-target-shim.

mysticatea avatar mysticatea commented on May 24, 2024

Ah, if there are arguments, a call of EventTarget(events) defines new constructor.
So how to use event-target-shim in ES5 is below:

//-----------------------------------------------------------------------------
// No attribute listeners.
function Foo() {
    EventTarget.call(this);
}
Foo.prototype = Object.create(EventTarget.prototype, {
    constructor: {
        value: Foo,
        configurable: true,
        writable: true
    },

    //....
});

//-----------------------------------------------------------------------------
// With attribute listeners.
function Foo() {
    EventTarget.call(this);
}
Foo.prototype = Object.create(EventTarget("message", "error").prototype, {
    constructor: {
        value: Foo,
        configurable: true,
        writable: true
    },

    //....
});

//-----------------------------------------------------------------------------
// With attribute listeners as an array.
function Foo() {
    EventTarget.call(this);
}
Foo.prototype = Object.create(EventTarget.apply(null, events).prototype, {
    constructor: {
        value: Foo,
        configurable: true,
        writable: true
    },

    //....
});

Now, I'm not sure this enhancement has a value.
I will add documents for ES5.

from event-target-shim.

nickdesaulniers avatar nickdesaulniers commented on May 24, 2024

That's still not correct. The use of call/apply on a constructor messes up this in the constructor function.

function Foo () { console.log(this) }
new Foo // Object { }
Foo.apply(null, []) // Window

from event-target-shim.

mysticatea avatar mysticatea commented on May 24, 2024

No, EventTarget(...types) is a function, not a constructor.
Please see again, class Foo extends EventTarget("message") is not class Foo extends new EventTarget("message")
Also, I conformed to work my example codes.

from event-target-shim.

nickdesaulniers avatar nickdesaulniers commented on May 24, 2024

wrote a patch for this

from event-target-shim.

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.