第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

nodejs創(chuàng)建一個(gè)“數(shù)據(jù)容器”

nodejs創(chuàng)建一個(gè)“數(shù)據(jù)容器”

慕妹3146593 2022-06-09 16:57:04
我在 Java 中有一種“json 數(shù)據(jù)容器”,但我目前在一個(gè) JavaScript 項(xiàng)目中工作,我想像通常在 Java 中那樣保存數(shù)據(jù):https ://hastebin.com/arajusubum.cs這是我在 Java 中的“容器”類,我嘗試在 JavaScript 中重新創(chuàng)建它,如下所示:const fs = require("fs");class Container {    constructor(path) {        this._path = path;        this._storage = "";    }    put(key, value) {        console.log(`${key}: ${value}`);        this._storage[key] = value;        console.log(this._storage);    }    get(key) {        if(!this._storage.includes(key)) return null;        return this._storage[key];    }    flush() {        const jsonString = JSON.stringify(this._storage);        fs.writeFile(this._path, jsonString, 'utf8', function (err) {            if (err) {                console.log("An error occured while writing JSON Object to File.");                return console.log(err);            }        });    }}module.exports = Container;但它不起作用,這意味著如果我嘗試輸出類對(duì)象,它不會(huì)引發(fā)任何錯(cuò)誤并且不會(huì)發(fā)生任何事情。這就是我將它添加到我的代碼中的方式:const Container = require("../classes/Container");......const newContainer = new Container("./test.json");newContainer.put("taskID", "1234");console.log(newContainer);
查看完整描述

1 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

這解決了我的問(wèn)題:

this._storage = {};

更改this._storage = ""this._storage = {};


查看完整回答
反對(duì) 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)