Chaining a function in JavaScript?

前端 未结 4 452
鱼传尺愫
鱼传尺愫 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:31

    getItem('names').addItem('Bill').getItem('names')
    

    I am confused, how do you get an item that has not been added???

    getItem returns an object contains addItem method, and addItem method returns an object contains getItem method

    Anyway, have a look the following tutorial. It does not completely solve your problem, but will give you an idea.

    http://guanfenglin.spaces.live.com/blog/cns!4E0822BF6C959B7F!668.entry

提交回复
热议问题