小编K_d*_*dev的帖子

ES6:无法从类创建对象

我正在尝试从“存储”类创建对象,在该类中我可以在地图中存储多个键值(使用ES6),但无法正常工作。

它甚至没有抛出错误,我在做什么错?

这是我的代码:

class Storage
{
    constructor( pKey, pValue )
    {
        this.key = pKey;
        this.value = pValue;
        this.map = new Map( [ pKey, pValue ] );
        console.log( this.map );//current output: (nothing)
    }


    set( pKey, pValue )
    {
        this.map.set( pKey, pValue );
    }

    get( pKey )
    {
        var result = this.map.get( pKey );
        return result;
    }

}

var myStorage = new Storage( "0", "test" );

console.log( myStorage.get( "0" ) );//espected output: "test" | current output: (nothing)
Run Code Online (Sandbox Code Playgroud)

javascript frontend class

4
推荐指数
1
解决办法
754
查看次数

标签 统计

class ×1

frontend ×1

javascript ×1