Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
120
rated 0 times [  124] [ 4]  / answers: 1 / hits: 22237  / 14 Years ago, thu, february 10, 2011, 12:00:00

Hi I don't know whether this is my mistake in understanding Javascript prototype object ..



Well to be clear I'm new to the Javascript singleton concept and lack clear cut knowledge in that but going through some referral sites I made a sample code for my system but it's giving out some errors which I couldn't find why so I'm asking for your help. My code is:



referrelSystem = function(){
//Some code here
}();


Prototype function:



referrelSystem.prototype.postToFb = function(){
//Some Code here
};


I get an error saying prototype is undefined!



Excuse me i thought of this right now



EDIT



I have used like this:



referrelSystem = function(){
return{
login:getSignedIn,
initTwitter:initTw
}
};


Is this causing an issue?


More From » object

 Answers
220

Update: Seeing your updated code, the return from referrelSystem won't work as expected, since return values are discarded when calling new referrelSystem().



Rather than returning an object, set those properties to this (the instance of referrelSystem that gets constructed):



var referrelSystem = function () {
// I assume you have other code here

this.login = getSignedIn;
this.initTwitter = initTw;
};

[#93804] Tuesday, February 8, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mitchell

Total Points: 95
Total Questions: 110
Total Answers: 87

Location: Gabon
Member since Thu, Jul 15, 2021
3 Years ago
mitchell questions
;