js: Make 'Mopidy()' work without 'new'

This commit is contained in:
Stein Magnus Jodal 2013-01-16 20:38:52 +01:00
parent 7083729930
commit f675a7e01d
4 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,10 @@
/*global bane:false, when:false*/
function Mopidy(settings) {
if (!(this instanceof Mopidy)) {
return new Mopidy(settings);
}
this._settings = this._configure(settings || {});
this._console = this._getConsole();

View File

@ -48,6 +48,15 @@ buster.testCase("Mopidy", {
new Mopidy({webSocket: {}});
refute.called(this.webSocketConstructorStub);
},
"works without 'new' keyword": function () {
var mopidyConstructor = Mopidy; // To trick jshint into submission
var mopidy = mopidyConstructor({webSocket: {}});
assert.isObject(mopidy);
assert(mopidy instanceof Mopidy);
}
},

View File

@ -1,6 +1,6 @@
/*! Mopidy.js - built 2012-12-04
/*! Mopidy.js - built 2013-01-16
* http://www.mopidy.com/
* Copyright (c) 2012 Stein Magnus Jodal and contributors
* Copyright (c) 2013 Stein Magnus Jodal and contributors
* Licensed under the Apache License, Version 2.0 */
/**
@ -910,6 +910,10 @@ define(['module'], function () {
/*global bane:false, when:false*/
function Mopidy(settings) {
if (!(this instanceof Mopidy)) {
return new Mopidy(settings);
}
this._settings = this._configure(settings || {});
this._console = this._getConsole();

File diff suppressed because one or more lines are too long