2

It seems that this is not possible. Is there another neat way of accomplishing this?

// Our transitions class
function Transitions() {
    this.fade = function() {
            this.create = function() {
                alert('you have arrived at the create method of the fade class');
            }
    }
}

1 Answer 1

3

This is possible. The way you are using it now.

You can do this to call a create function:

var x = new Transitions();
// Here .create does not exists
x.fade(); // Here the create function will be generated to the this object
x.create(); // Does alert

But you probably want something like this:

function Transitions() {
        // Create an object with an sub object
        this.fade = {
                create : function() {

                    alert('you have arrived at the create method of the fade class');
                }
        }

    }

var x = Transitions();
x.fade.create(); // Call the sub object
Sign up to request clarification or add additional context in comments.

3 Comments

aah, so the colon instead of equal sign makes the entire difference, cool.
@MattiasSvensson well, in Niels example, fade is an object, not a function
True, I have changed this.fade from a function into an object by using the { }, if I would use the [] it would be an array.

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.