D
Daniel
Hi,
I was reading Douglas Crockford's article on prototypal inheritance at
http://javascript.crockford.com/prototypal.html.
I think it also relates to a post back in Dec 2005.
The mechanism discussed was:
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
Towards the end of the article, Douglas says that "For convenience, we
can create functions which will call the 'object' function for us, and
provide other customizations such as augmenting the new objects with
privileged functions. I sometimes call these maker functions."
Any chance someone can give an example?
By 'priveleged' I want a function that can access the private
variables in the object. eg
function F() {
var private_var = "this is private";
this.get_private_var = function() { return private_var; }
}
So, this amounts to being able to augment f with 'get_private_var'
after doing 'f = new F()' , instead of defining get_private_var within
the scope of the F constructor function as per the above fragment.
Many Regds,
Daniel
I was reading Douglas Crockford's article on prototypal inheritance at
http://javascript.crockford.com/prototypal.html.
I think it also relates to a post back in Dec 2005.
The mechanism discussed was:
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
Towards the end of the article, Douglas says that "For convenience, we
can create functions which will call the 'object' function for us, and
provide other customizations such as augmenting the new objects with
privileged functions. I sometimes call these maker functions."
Any chance someone can give an example?
By 'priveleged' I want a function that can access the private
variables in the object. eg
function F() {
var private_var = "this is private";
this.get_private_var = function() { return private_var; }
}
So, this amounts to being able to augment f with 'get_private_var'
after doing 'f = new F()' , instead of defining get_private_var within
the scope of the F constructor function as per the above fragment.
Many Regds,
Daniel