diff --git a/js/Disposable.ts b/js/Disposable.ts index 011945a4..e4c61752 100644 --- a/js/Disposable.ts +++ b/js/Disposable.ts @@ -22,7 +22,8 @@ class Disposable { public readonly _disposeEmitter: TEmitter = new TinyEmitter(); public isDisposed = false; - public constructor() { + // Disposable should only be used by subtypes, no need to instantiate one on its own. + protected constructor() { if ( assert ) { // Wrap the prototype dispose method with a check. NOTE: We will not catch devious cases where the dispose() is diff --git a/js/DisposableTests.ts b/js/DisposableTests.ts index 58ac3bec..9967dd01 100644 --- a/js/DisposableTests.ts +++ b/js/DisposableTests.ts @@ -13,9 +13,13 @@ QUnit.module( 'Disposable' ); QUnit.test( 'Disposable basics', assert => { assert.ok( true, 'initial test' ); - const object1 = new Disposable(); + class MyDisposable extends Disposable { + public constructor() { super();} + } + + const object1 = new MyDisposable(); assert.ok( !!object1.disposeEmitter, 'disposeEmitter needed' ); - const object2 = new Disposable(); + const object2 = new MyDisposable(); object1.disposeEmitter.addListener( () => object2.dispose() ); assert.ok( !object1.isDisposed, '1 is not disposed' );