From 3d2b86032e2e886934efa534c3129d3e51227780 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Tue, 9 Aug 2016 01:12:34 -0400 Subject: [PATCH] added `has` method to test if buffer exists --- Tone/core/Buffers.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Tone/core/Buffers.js b/Tone/core/Buffers.js index 9f79720f..5c813054 100644 --- a/Tone/core/Buffers.js +++ b/Tone/core/Buffers.js @@ -49,6 +49,16 @@ define(["Tone/core/Tone", "Tone/core/Buffer"], function (Tone) { Tone.extend(Tone.Buffers); + /** + * True if the buffers object has a buffer by that name. + * @param {String|Number} name The key or index of the + * buffer. + * @return {Boolean} + */ + Tone.Buffers.prototype.has = function(name){ + return this._buffers.hasOwnProperty(name); + }; + /** * Get a buffer by name. If an array was loaded, * then use the array index. @@ -57,10 +67,10 @@ define(["Tone/core/Tone", "Tone/core/Buffer"], function (Tone) { * @return {Tone.Buffer} */ Tone.Buffers.prototype.get = function(name){ - if (this._buffers.hasOwnProperty(name)){ + if (this.has(name)){ return this._buffers[name]; } else { - throw new Error("Tone.Buffers: no buffer named"+name); + throw new Error("Tone.Buffers: no buffer named "+name); } };