मैं प्रोटोटाइप को ओवरराइट करने से रोकने के लिए क्रॉकफोर्ड शिम पर पढ़ रहा हूं, और समझता हूं कि यह कभी-कभी अंत/सभी-समाधान नहीं होता है। मैं यह भी समझता हूं कि ES5 Shim इसके लिए एक व्यवहार्य विकल्प हो सकता है। मैंने this post which provides a more robust, secure alternative भी पढ़ा।क्रॉकफ़ोर्ड के ऑब्जेक्ट को समझना। क्रीम
फिर भी, मैं जानना चाहता हूं कि उसका Object.create
शिम "कह रहा है" और फिर "कर रहा है।" क्या कोई मुझे बता सकता है कि मेरी स्पष्टीकरण टिप्पणियां सही हैं या नहीं?
if (typeof Object.create === 'undefined') {
//If the browser doesn't support Object.create
Object.create = function (o) {
//Object.create equals an anonymous function that accepts one parameter, 'o'.
function F() {};
//Create a new function called 'F' which is just an empty object.
F.prototype = o;
//the prototype of the 'F' function should point to the
//parameter of the anonymous function.
return new F();
//create a new constructor function based off of the 'F' function.
};
}
//Then, based off of the 'Lost' example in the Crockford book...
var another_stooge = Object.create(stooge);
//'another_stooge' prototypes off of 'stooge' using new school Object.create.
//But if the browser doesn't support Object.create,
//'another_stooge' prototypes off of 'stooge' using the old school method.
इस तरह, 'कठपुतली' वस्तु के प्रोटोटाइप ओवरराइट नहीं किया जा सकता है जब हम 'another_stooge' के लिए सामान को बढ़ाने। 'कन्स्ट्रक्टर' का उपयोग करके 'स्टूज' प्रोटोटाइप को रीसेट करने की आवश्यकता नहीं है।
अग्रिम धन्यवाद,
-k
ए-हा! मैने सोचा कि मैंने पा लिया। धन्यवाद शेख ... आपकी मदद बहुत सराहना की है !!! – kaidez
आप सबसे अधिक स्वागत करते हैं :-) –