function Person(firstName, lastName) { var prot = {}; var self = this; prot.aProtectedMethod = function() { alert("Protected method"); }; if (self._protCounter > 0) { return prot; } } function Employee(firstName, lastName, department) { var self = this; self._protCounter = (self._protCounter ? self._protCounter + 1 : 1); var prot = Person.call(this, firstName, lastName); self._protCounter--; self.getName = function() { prot.aProtectedMethod(); return firstName + " " + lastName; }; if (self._protCounter > 0) { return prot; } } var Temp = function() {}; Temp.prototype = Person.prototype; Employee.prototype = new Temp();
Listing 10: Namensräume/Pakete
if (!window.de) window.de = {}; if (!de.heise) de.heise = {}; if (!de.heise.ix) de.heise.ix = {}; if (!de.heise.ix.test) de.heise.ix.test = {}; de.heise.ix.test.Person = function(firstName, lastName) { // Implementierung siehe vorheriges Listing } de.heise.ix.test.Employee = function (firstName, lastName, department) { // Implementierung siehe vorheriges Listing } var Temp = function() {}; Temp.prototype = de.heise.ix.test.Person.prototype; de.heise.ix.test.Employee.prototype = new Temp(); var max = new de.heise.ix.test.Employee("Max", "Muster", "Sales");
Weiterlesen nach der Anzeige
Listing 11: Dokumentations-Kommentar
/** * Constructor for a Person object. * @param {String} firstName the person's first name. * @param {String} lastName the persons's last name. */ de.heise.ix.test.Person = function(firstName, lastName) { // ... }