在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

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

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

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

clipboard.png

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

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í)間保存此類數(shù)據(jù)?
回答
編輯回答
撥弦

stringify的時(shí)候檢測到某個(gè)value是function的時(shí)候tostring一下?但問題還是很多的

2017年12月27日 16:45