Throwing error if settings / arguments are undefined is this a good breakout function? var _ = require("underscore");

var checkSettingsUndefined = function(settings){
    if(_.isEmpty(settings)){
        throw new Error("settings are empty");   
    }
}

var Class = function(settings){
    checkSettingsUndefined(settings);
    this.settings = settings;
}

Class.prototype.settings = function(){
    return this.settings;
}

module.exports = Class;


and here's my unit test

it("empty settings should throw error", function(){
    var Class = require("Class.js");
    expect(function(){
        return new Class();
    }).to.throwException(function (e) {
        expect(e.message).to.be("settings are empty");
    });
});
The abstraction is good but the tight coupling is bad.  The only real use case for checkSettingsUndefined is for your Class object.

Here is an example of a more generic method, it just takes an array of validation objects that will be run on their associated calling args.

/**
 * @param  {[Object]} validationArray Array of validation configs 
 * that follow the api of
    {
        fn: function(value) {},
        message: ''
    }
 * @return Function
 */

function createArgValidatorFn(validationArray) {

    return function() {
        var argValue,
            validationFn,
            args = arguments;

        validationArray.forEach(function(obj, index) {
            validationFn = obj.fn;
            argValue = args[index];

            if (validationFn(argValue)) {
                throw new Error('argument[' + index + '] : '  + obj.message);
            }

        });
    }
}


You can use in Class by doing:

var classValidationFn = createArgValidatorFn([{
        fn: _.isEmpty,
        message: 'settings are empty'
    }
]);

var Class = function(settings){
    classValidationFn.apply(this, arguments);
    this.settings = settings;
};


This will allow to stuff like:

var fn = createArgValidatorFn([{
        fn: function(val) {
            return typeof val !== 'string'
        },
        message: 'Argument must be a string'
    }, {
        fn: function(val) {
            return !val;
        },
        message: 'Argument must be a truthy'
    }
])


fn('a');


  "argument[1] : Argument must be truthy"