简体   繁体   English

我的方法始终警告Object [Object object]

[英]My methods always alert Object [Object object]

I don't know why the methods returns always [Object object]. 我不知道为什么方法总是返回[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? 我需要做什么?

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. 我假设DatabasePlugin实例的get_account_profiles返回一个字符串。

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. 确保在您调用SetDataDB的范围内可以访问DatabasePlugin

你忘记了肠胃外科吗?

new DatabasePlugin().get_account_profiles('settings_account')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM