Sign In/My Account | View Cart  
advertisement

Article:
 Prototype: Easing AJAX's Pain
Subject: How do I add private methods?
Date: 2006-11-22 06:36:01
From: Raphael.Stolt

I am still in the dark on how I define method to/in an private scope?


I tried to play around with the following source but couldn't get to work.


Any hint or better a solution would be appreciated and solve for me another part in the javascript 'puzzle'.


var Headline = Class.create();
Headline.prototype = {


initialize: function() {
this.responseText = '';
this.isAtttachedUploadRemoved = false;

},
getResponseText: function () {
if(this.isAttachedUploadRemoved) {
return this.responseText;
}
},
removeAttachedUpload: function(uploadId, headlineId) {
alert('Call to remove method with '+ uploadId + ' ' + headlineId);
this.setAttachedUploadRemoveStatus(true);
this.responseText = 'blah 2006';
},

/** this method should be private
* so I can make private calls i.e. in the removeAttachedUpload method and not from the
* outer scope
*/
setAttachedUploadRemoveStatus: function (status) {
this.isAtttachedUploadRemoved = status;
}
}


Previous Message Previous Message   Next Message Next Message


Titles Only Titles Only Newest First
  • How do I add private methods?
    2006-11-22 08:58:26 bwp [Reply]

    See this really good article on mimicking private access specifiers in JavaScript:


    http://www.crockford.com/javascript/private.html


    Cheers.


Sponsored By: