1

I need to create a dynamic object. I'll store all of these objects in an array. Each object will have some property and objects. After the object is created, I need to do an auto execute method from it. I can't call in my code like this: obj.doSomething because some users have 2 objects, and other users 300 objects.

Something like this:

class Select {
    constructor(el,input){
        this.el = el; 
        this.input = input
    }

    AutoExecture(){
        // I need these function to execute immediately;
        console.log(this.input);
    } 
}
2
  • You can can this.AutoExecture() inside your constructor. Commented Sep 12, 2018 at 14:39
  • Thank you . That's what I needed . Commented Sep 12, 2018 at 14:56

1 Answer 1

1

Perhaps you want something like this:

class Select {
    constructor(el,input){
        this.el = el; 
        this.input = input;

        // This code will autoExecute when you construct an object
        console.log(this.input);
    }
}

You can run this code in the console with something like:

var a = new Select("hi", "bye");
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.