我正在尝试从“存储”类创建对象,在该类中我可以在地图中存储多个键值(使用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)