Chaining a function in JavaScript?

前端 未结 4 453
鱼传尺愫
鱼传尺愫 2020-12-19 10:59

I want to make a function that add an item to my localStorage object. E.g.:

alert(localStorage.getItem(\'names\').addItem(\'Bill\').getItem(\'names\'));
         


        
4条回答
  •  伪装坚强ぢ
    2020-12-19 11:19

    This is impossible.

    If getItem('names') returns Bill, you can't call addItem on it.
    It would be possible to add addItem and getItem methods to every item in the storage, but it would be a horrible idea.

提交回复
热议问题