From: John G Harris on
On Fri, 7 May 2010 at 05:54:52, in comp.lang.javascript, Michael Haufe
("TNO") wrote:
>On May 7, 2:27�am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>> Hi Everybody,
>>
>> What is your most challenging interview question?
>
>
>Q: How would you implement a constructor that inherits a method from
>it's prototype that has access to it's instance private variables?
<snip>

I'd point out, politely I hope, that you wrote the question without
enough proof-reading :-)

Although a constructor can inherit a method from it's [sic] prototype
there isn't much point in its doing so, and there's no way a
constructor's method can access an instance's data before that data has
been created. Also, I'd ask what you mean by 'private'.

John
--
John Harris
From: Ry Nohryb on
On May 7, 2:54 pm, "Michael Haufe (\"TNO\")"
<t...(a)thenewobjective.com> wrote:
> On May 7, 2:27 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>
> > Hi Everybody,
>
> > What is your most challenging interview question?
>
> Q: How would you implement a constructor that inherits a method from
> it's prototype that has access to it's instance private variables? In
> other words if I had:
>
> function Foo(a){
>     ...
>     var _foo = a
>     ...
>
> }
>
> how would you use prototypical inheritance so that the following is
> possible:
>
> var obj1 = new Foo("one"),
>     obj2 = new Foo("two");
>
> obj1.thing() //"one"
> obj2.thing() //"two"

I'll bite... :-)

var clase= (function claseBuilder () {
var instances= [];
var getters= [];
var clase= {};

clase.getPrivate= function () {
return getters[instances.indexOf(this)]();
};

clase.pushGetter= function (instance, getter) {
instances.push(instance);
getters.push(getter);
};

return clase;
})();

function subclase (private) {
o= {};
o.__proto__= clase;
clase.pushGetter(o, function () { return private });
return o;
}

var a= subclase(33);
var b= subclase(27);

[a.hasOwnProperty("getPrivate"), a.hasOwnProperty("getPrivate")]
--> [ false, false ]
[a.getPrivate(), b.getPrivate()]
--> [ 33, 27 ]

--
Jorge.
From: nick on
On May 7, 8:54 am, "Michael Haufe (\"TNO\")"
<t...(a)thenewobjective.com> wrote:

> Q: How would you implement a constructor that inherits a method from
> it's prototype that has access to it's instance private variables? In
> other words if I had:

Argh! "Its" ... "its" ... "its."

It's a declension. Not possessive, not a contraction. Like "his" or
"her," it needs no apostrophe.

Sorry, Michael, but this is like the 20th time I've seen this mistake
on cljs in the last 24 hours or so... figured it was time to say
something.
From: VK on
On May 7, 11:27 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> Hi Everybody,
>
> What is your most challenging interview question?
>
> Mine:
> "What do you think of jQuery?"

IMO it is challenging for c.l.j. only - in the aspect to say about
jQuery the most nasty things in the most nasty way to fully satisfy
some regulars and "regulars" pseudo-ethical needs yet do not touch
occasionally in any shall perform way the preferred coding and
structuring habits of neither one of them. :-)) :-|

Presuming the purpose of any job interview being to get the job and
not to make a loud public statement about one's personal preferences -
presuming that the challenge gets much easier.
Learn company's profile. Visit their website and study the used
internal coding. Study the version vector using the Wayback Machine
( http://www.archive.org/web/web.php ). Whatever is abandoned or
changed - it happened for a reason. Even if that reason was a CFO's
wife occasional complain that "these thingies are looking kinda yaky,
darling..." - it is a hell of important reason to not promote those
"thingies" right at the moment. At the hot bloody summer of 1998 the
customer company's CEO was a fan of IE4 and CFO was a fan of NN4. The
challenge was to please both while talking about browsers with both
sitting in front of you. That was a challenge. This is just a light
mind gim. :-)
a) Mention your concerns (w/o any explicit judgment) about $()
function compatibility between jQuery and Prototype.js (
http://docs.jquery.com/Using_jQuery_with_Other_Libraries )
This way you show that you are neither a jQuery fan nor a jQuery
hater, but a open-minded professional. Remember that no one want a
rwar fanatic on board.
b) Mention some most recent jQuery bug for a recent version of 2nd
wave browsers (Safari, Chrome, Opera): http://dev.jquery.com/timeline/
This way you show your timely response to the browser market dynamics.

Relax and wait for the next question.
From: Ry Nohryb on
On May 7, 7:35 pm, Ry Nohryb <jo...(a)jorgechamorro.com> wrote:
> On May 7, 2:54 pm, "Michael Haufe (\"TNO\")"
>
>
>
>
>
> <t...(a)thenewobjective.com> wrote:
> > On May 7, 2:27 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>
> > > Hi Everybody,
>
> > > What is your most challenging interview question?
>
> > Q: How would you implement a constructor that inherits a method from
> > it's prototype that has access to it's instance private variables? In
> > other words if I had:
>
> > function Foo(a){
> >     ...
> >     var _foo = a
> >     ...
>
> > }
>
> > how would you use prototypical inheritance so that the following is
> > possible:
>
> > var obj1 = new Foo("one"),
> >     obj2 = new Foo("two");
>
> > obj1.thing() //"one"
> > obj2.thing() //"two"
>
> I'll bite... :-)
>
> var clase= (function claseBuilder () {
>   var instances= [];
>   var getters= [];
>   var clase= {};
>
>   clase.getPrivate= function () {
>     return getters[instances.indexOf(this)]();
>   };
>
>   clase.pushGetter= function (instance, getter) {
>     instances.push(instance);
>     getters.push(getter);
>   };
>
>   return clase;
>
> })();
>
> function subclase (private) {
>   o= {};
>   o.__proto__= clase;
>   clase.pushGetter(o, function () { return private });
>   return o;
>
> }
>
> var a= subclase(33);
> var b= subclase(27);
>
> [a.hasOwnProperty("getPrivate"), a.hasOwnProperty("getPrivate")]
> --> [ false, false ]
> [a.getPrivate(), b.getPrivate()]
> --> [ 33, 27 ]
>
> --
> Jorge.

Version 2:

var subClase;
var clase= (function claseBuilder (instances, getters, clase) {
clase.getPrivate= function () {
return getters[instances.indexOf(this)]();
};
subClase= function subClaseBuilder (private, o) {
(o= {}).__proto__= clase;
instances.push(o);
getters.push(function () { return private });
return o;
};
return clase;
})([], [], {});


var a= subClase(33);
var b= subClase(27);


[a.hasOwnProperty("getPrivate"), b.hasOwnProperty("getPrivate")]
--> [ false, false ]
[a.getPrivate(), b.getPrivate()]
--> [ 33, 27 ]
--
Jorge.