鍍金池/ 問答/人工智能  HTML5  網(wǎng)絡(luò)安全  HTML/ localStorage如何存儲方法類型數(shù)據(jù)?

localStorage如何存儲方法類型數(shù)據(jù)?

一個面包屑導(dǎo)航功能,單獨封裝了一個組件。在關(guān)閉當(dāng)前tab的時候,需要跳轉(zhuǎn)至上一個path。

clipboard.png

我考慮在父級調(diào)用這個組件時將history傳過去,然后就可以通過history.push()進(jìn)行跳轉(zhuǎn)。
這時我想到數(shù)據(jù)持久化的問題,便打算將history保存至localStorage
但是因為JSON.stringify(function...)會將方法體過濾:
ECMASCript官方也特意強調(diào)了這一點:

It does not attempt to impose ECMAScript’s internal data representations on other programming languages. Instead, it shares a small subset of ECMAScript’s textual representations with all other programming languages.

所以想問一下:

  1. 如何將方法體存入localStorage?
  2. 如果不采取存入localStorage的方法,那么有什么辦法可以長時間保存此類數(shù)據(jù)?
回答
編輯回答
撥弦

stringify的時候檢測到某個value是function的時候tostring一下?但問題還是很多的

2017年12月27日 16:45