मुझे एक फ़ंक्शन मिल गया है:
फ़ंक्शन createOrLoadDB (होस्ट) {var db = JSON.parse (window.localStorage.getItem (होस्ट)) अगर (डीबी == रिक्त) {db = new InitDB (होस्ट)} और {db .__ प्रोटोज़ = InitDB.prototype} वापसी डीबी}
मुझे ऐसा लगता है कि यह काम करेगा, लेकिन जब मैं db.flushDB ()
मुझे
TypeError: Object # & lt; एक InitDB & gt; कौन सा मजेदार है, क्योंकि मुझे मेरे ऑब्जेक्ट डीईफ़ में मिला है: फ़ंक्शन InitDB (होस्ट) {.. । This stuff.flushDB = function () {window.localStorage.setItem (this.host, JSON.stringify (this))} ... सामान}
है, मैं कुछ भूल गया हूँ __ प्रोटो __
ने इसे # & lt; एक InitDB & gt;
कहते हैं, लेकिन यह अभी भी तरीकों को नहीं उठा रहा है ...
अपना flushDB
विधि को InitDB.protoype
में जोड़ें। अन्यथा यह विधि केवल InitDB
के द्वारा बनाई गई वस्तुओं में दिखाई देगी।
फ़ंक्शन InitDB (होस्ट) {// init stuff यहां, घटाएं this.flushDB} InitDB.prototype.flushDB = कार्य () {window.localStorage.setItem (this.host, JSON.stringify (this)); };
Comments
Post a Comment