0

I don't know why the methods returns always [Object object]. My code it's here:

function SetDataDB(){
    alert(new DatabasePlugin.get_account_profiles('settings_account'));
}

var DatabasePlugin = {
    insert_account_profiles : function(array, parameter){
        window.localStorage.setItem(parameter, array);
    },

    get_account_profiles: function(parameter){
        return "Hola";
    }
};

It always returns me an object but not specified. What do I have to do?

6
  • Where does DatabasePlugin come from? Commented Nov 21, 2012 at 17:22
  • @AlexK. the methods are on different classes so i need the new Commented Nov 21, 2012 at 17:23
  • @Asad from the homemade class DatabasePlugin :) Commented Nov 21, 2012 at 17:24
  • @MarcOrtiz Which, when instantiated, gives you an object :) What seems to be the problem? Commented Nov 21, 2012 at 17:25
  • removing new gets you the string, as it stands its acting as a constructor so returns an object that is a new instance of get_account_profiles (which will show as [object object] if converted to a string) Commented Nov 21, 2012 at 17:25

2 Answers 2

1

Try this:

function SetDataDB(){
    alert((new DatabasePlugin).get_account_profiles('settings_account'));
}

I'm assuming the get_account_profiles of a DatabasePlugin instance returns a string.

EDIT: As per your edit, you need to define the object before you access its properties. Make sure DatabasePlugin is accessible in the scope you are invoking SetDataDB in.

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

3 Comments

it says me: object is not a function
@MarcOrtiz That means DatabasePlugin isn't a class, it is an object.
Yes it's an object. Because of this i didn't write the ()
1

did you forget the parentesis ?

new DatabasePlugin().get_account_profiles('settings_account')

1 Comment

could you please take a look at my question edited recently? Thanks

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.