fix option setting

master
Aaron Heckmann 13 years ago
parent 92f0a4ed49
commit 6ae031506a
  1. 16
      index.js
  2. 13
      lib/options.js
  3. 25
      test/options.js

@ -22,6 +22,9 @@ function gm (source, height, color) {
return new gm(source, height, color);
}
this._options = {};
this.options(this.__proto__._options);
this.data = {};
this._in = [];
this._out = [];
@ -54,8 +57,7 @@ function gm (source, height, color) {
}
var super = gm;
gm.subClass =
gm.setOptions = function subClass (options) {
gm.subClass = function subClass (options) {
function gm (source, height, color) {
if (!(this instanceof super)) {
return new gm(source, height, color);
@ -66,15 +68,7 @@ gm.setOptions = function subClass (options) {
gm.prototype.__proto__ = super.prototype;
gm.prototype._options = {};
var keys = Object.keys(options)
, i = keys.length
, key
while (i--) {
key = keys[i];
gm.prototype._options[key] = options[key];
}
gm.prototype.options(options);
return gm;
}

@ -3,4 +3,17 @@
module.exports = exports = function (proto) {
proto._options = {};
proto.options = function setOptions (options) {
var keys = Object.keys(options)
, i = keys.length
, key
while (i--) {
key = keys[i];
this._options[key] = options[key];
}
return this;
}
}

@ -0,0 +1,25 @@
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
var assert = require('assert')
module.exports = function (_, dir, finish, gm) {
var sub = gm.subClass({ subclassed: true });
var s = sub('test').options({ setWithMethod: 2 });
var g = gm('test').options({ hellowwww: 'there' });
assert.equal(2, s._options.setWithMethod);
assert.equal(true, s._options.subclassed);
assert.equal('there', g._options.hellowwww);
assert.equal(undefined, g._options.setWithMethod);
assert.equal(undefined, s._options.hellowwww);
assert.equal(undefined, g._options.subclassed);
var s2 = sub('another');
assert.equal(true, s2._options.subclassed);
assert.equal(undefined, s2._options.setWithMethod);
finish();
}
Loading…
Cancel
Save