Re: Nonconstructors

2017-04-28 Thread Tab Atkins Jr.
On Mon, Apr 24, 2017 at 10:53 PM, Raul-Sebastian Mihăilă wrote: > On Tue, Apr 25, 2017 at 12:15 AM, Tab Atkins Jr. > wrote: >> >> >> The obvious question is, why do you want to use `this`? >> >> ~TJ > > > > For cases such as a debounce function: > >

Re: Nonconstructors

2017-04-24 Thread Raul-Sebastian Mihăilă
On Tue, Apr 25, 2017 at 12:15 AM, Tab Atkins Jr. wrote: > > The obvious question is, why do you want to use `this`? > > ~TJ > For cases such as a debounce function: ```js const debounce = (func, delay) => { let timeout; return function (...args) {

Re: Nonconstructors

2017-04-24 Thread T.J. Crowder
On Tue, Apr 25, 2017 at 6:19 AM, Jordan Harband wrote: > Arrow functions are not constructible; just use one of those. He said he wanted to use `this` within it (I'm assuming in a non-closed-over way)... -- T.J. Crowder ___

Re: Nonconstructors

2017-04-24 Thread Jordan Harband
Arrow functions are not constructible; just use one of those. On Mon, Apr 24, 2017 at 2:55 PM, J Decker wrote: > function Entity() { > if (this instanceof Entity) throw new Error("Please do not call with new"); > } > > oh the other side; you can bind this to a simple function

Re: Nonconstructors

2017-04-24 Thread J Decker
function Entity() { if (this instanceof Entity) throw new Error("Please do not call with new"); } oh the other side; you can bind this to a simple function call... function f() { } var fWithThis = f.bind( {} /*Something to use as 'this' */ ) call with fWithThis() and f's this will be the

Re: Nonconstructors

2017-04-24 Thread Michał Wadas
You can use: const foo = { bar() { // Not constructible } }; new foo.bar; //TypeError: foo.bar is not a constructor On Mon, Apr 24, 2017 at 10:42 PM, Raul-Sebastian Mihăilă < raul.miha...@gmail.com> wrote: > I have a dilemma. I like how typically the built-in methods are not >

Re: Nonconstructors

2017-04-24 Thread Tab Atkins Jr.
On Mon, Apr 24, 2017 at 1:42 PM, Raul-Sebastian Mihăilă wrote: > I have a dilemma. I like how typically the built-in methods are not > constructors (like Array.prototype.forEach). I have cases in which I'm > creating a function in which I want to use `this` but I would

Nonconstructors

2017-04-24 Thread Raul-Sebastian Mihăilă
I have a dilemma. I like how typically the built-in methods are not constructors (like Array.prototype.forEach). I have cases in which I'm creating a function in which I want to use `this` but I would like the function to not be constructible. There are ways of doing this: - checking new.target -