1

I can not return values bools / strings using the following convention.

http://jsfiddle.net/eQWyY/

<input id="lol" type="text" value="ahh" />

<script>
function test() {
    var flag = false;
    if ($('#lol').val()) {
        alert($('#lol').val()); //"sanity check - pass"
        flag = true;
    }
    return flag;
};

function modal() {};
var m = new modal();

modal.prototype.init = function(x) {
    this.input = x;
    this.modals = {};
    this.initModalFrames();
    this.executeLogic();
}

modal.prototype.initModalFrames = function() {
    for (i in this.input) {
        this.modals[i] = {
            handle :    this.input[i].handle,
            frame :     this.input[i].frame,
            logic :     this.input[i].logic ? this.input[i].logic : null
        };
    }
}

modal.prototype.executeLogic= function() {
    var s = this;
    $.each(this.modals, function(i, o) {
        if(s.modals[i].logic != null) {
            var x = s.modals[i].logic.call();
            if(x) {
                alert('true');
            }
            else {
                //Always evaluates to false
                alert('false');
            }
        }
    });
}

m.init([
      {handle: '#handle1', frame: '#frame2', logic: function() {test();}},
]);

</script>

The function does not seem to return anything and always evaluates to false. What am I doing wrong here?

1 Answer 1

3

Your logic handler should return the result of test execution:

{ handle: '#handle1', frame: '#frame2', logic: function() { return test(); } }

or simpler:

{ handle: '#handle1', frame: '#frame2', logic: test }

DEMO: http://jsfiddle.net/eQWyY/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.