Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 809 Bytes

File metadata and controls

39 lines (29 loc) · 809 Bytes

Function.prototype.new

To call a constructor, we need to use the new syntax. Its not easy to use with a hyper function. BetterJS provide another way to call constructors:

Constructor.new( /* ... */ );

Usage

import 'https://better-js.fenz.land/src/function-prototype/new.js';

class Foo {
	constructor( name, )
	{
		this.name= name;
	}
}

Foo.new( 'foo', ); // Foo{ name:'foo', }

[ 'foo', 'bar', 'baz', ].map( Foo.new, ); // Array [ Foo{} × 3 ]

'foo' |> Foo.new; // Foo{ name:'foo', }

identity

Currently, the value of .new a not identity unique, that means:

Foo.new !== Foo.new

We need WeakRef to implement the feature of identity unique without memory leak.

At that time, we will change to:

Foo.new === Foo.new