0

I want to have an object that accepts some input string with delimeters like "dog:cat:whale" and want the property inside "splittedText" to be an array of post-split input objects "spittedText[0] = dog, spittedText[1] = cat, spittedText[2] = whale".

The following is generic pseudocode of what I want to accomplish, but doesnt work...

function someObject(input) {
    this.splittedText=input.split(':');
}

To test, I should be able to do this:

theObject = new someObject("dog:cat:whale");
alert(someObject(theObject.splittedText[0])); // should print out dog

What am I doing wrong? How do I accomplish this?

2 Answers 2

1

You shouldn't be calling the function again.

alert(theObject.splittedText[0]);
Sign up to request clarification or add additional context in comments.

Comments

0

This works for me:

var someObj = new SomeObject("dog:cat:whale");

function SomeObject(str){
    this.splittedText = str.split(':');
}

alert(someObj.splittedText);

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.