473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new foo.prototype.b ar(x,y,z ) ?

kj


OK, here's another construct I've run into in the jQuery source
that I can't figure out. It looks like this:

return new jQuery.prototyp e.init( selector, context );

So basically, as far as I can tell, the returned value has the form

new obj.prototype.m ethod( args );

(In addition, FWIW, the function jQuery.prototyp e.init has several
explict return statements which, as far as I can tell, all end up
returning "this".)

What I find most confusing here is that when I check the constructor
property of the newly created object I find that it is *not*
jQuery.prototyp e.init. I.e. the boolean expression

( new jQuery.prototyp e.init( selector, context ) ).constructor
=== jQuery.prototyp e.init

evaluates to *false*. Even if I test the value of this.constructo r
at a breakpoint right at the top of jQuery.prototyp e.init, what I
get is Object, not jQuery.prototyp e.init. Contrast this behavior
with

function Foo () {
alert( this.constructo r === Foo );
}
x = new Foo();

In this case the alert dialog will display "true", as one would
expect.

I've tried many different variants of this test and I have never
been able to replicate the situation in which the constructor
property of the this object in the scope of a function that has
been called using the new keyword is anything other than the function
in question. These tests included the case in which the function
explicitly returns the this object. (I even ran some of these
tests in SpiderMonkey running on Linux to rule out the possibility
that what I was seeing was either a Firebug artefact or a quirk in
the Firefox implementation of Javascript. I got the same results.)

This is utterly baffling to me...

If anyone can explain to me what's going on I'd appreciate it!

Thanks!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Jan 27 '08 #1
3 1878
On Jan 28, 9:54 am, kj <so...@987jk.co m.invalidwrote:
OK, here's another construct I've run into in the jQuery source
that I can't figure out. It looks like this:

return new jQuery.prototyp e.init( selector, context );

So basically, as far as I can tell, the returned value has the form

new obj.prototype.m ethod( args );

(In addition, FWIW, the function jQuery.prototyp e.init has several
explict return statements which, as far as I can tell, all end up
returning "this".)

What I find most confusing here is that when I check the constructor
property of the newly created object I find that it is *not*
jQuery.prototyp e.init. I.e. the boolean expression

( new jQuery.prototyp e.init( selector, context ) ).constructor
=== jQuery.prototyp e.init

evaluates to *false*. Even if I test the value of this.constructo r
at a breakpoint right at the top of jQuery.prototyp e.init, what I
get is Object, not jQuery.prototyp e.init. Contrast this behavior
with

function Foo () {
alert( this.constructo r === Foo );
}
x = new Foo();

In this case the alert dialog will display "true", as one would
expect.

I've tried many different variants of this test and I have never
been able to replicate the situation in which the constructor
property of the this object in the scope of a function that has
been called using the new keyword is anything other than the function
in question. These tests included the case in which the function
explicitly returns the this object. (I even ran some of these
tests in SpiderMonkey running on Linux to rule out the possibility
that what I was seeing was either a Firebug artefact or a quirk in
the Firefox implementation of Javascript. I got the same results.)

This is utterly baffling to me...

If anyone can explain to me what's going on I'd appreciate it!

Thanks!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Try:
( new jQuery.prototyp e.init( selector, context ) ).constructor
== jQuery

and tell me what it says. Specifically, look for the following line of
code for a reference to the init constructors prototype:
jQuery.prototyp e.init.prototyp e = jQuery.prototyp e;
Jan 27 '08 #2
kj
In <97************ *************** *******@q77g200 0hsh.googlegrou ps.com"li****** *@gmail.com" <li*******@gmai l.comwrites:
>Try:
( new jQuery.prototyp e.init( selector, context ) ).constructor
== jQuery
>and tell me what it says.
Firebug at least reports that boolean expression as false.
>Specifically , look for the following line of
code for a reference to the init constructors prototype:
jQuery.prototy pe.init.prototy pe = jQuery.prototyp e;
I see, but still, the constructor is not jQuery...

Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Jan 27 '08 #3
kj <so***@987jk.co m.invalidwrites :
In <97************ *************** *******@q77g200 0hsh.googlegrou ps.com"li****** *@gmail.com" <li*******@gmai l.comwrites:
>>Try:
( new jQuery.prototyp e.init( selector, context ) ).constructor
== jQuery
>>and tell me what it says.

Firebug at least reports that boolean expression as false.
>>Specificall y, look for the following line of
code for a reference to the init constructors prototype:
jQuery.protot ype.init.protot ype = jQuery.prototyp e;

I see, but still, the constructor is not jQuery...
As I said in the previous thread, object.construc tor is unreliable
unless the person writing the constructor method has taken care that it
works.

You usually don't need it to work anyway, since instanceof works
better.

Joost.
Jan 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12174
by: Web Developer | last post by:
Hi, Comming from Java, it seems that prototype declarations are like abstract methods. I have not read classes in C++ yet, but prototype declarations are a strange concept. Any comments appreciated. WD
8
3746
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the bind function. The problem with Javascript is that the "this" operator is poorly overloaded and it is often hard to understand in the context of object-oriented javascript So, let's start with the definition:
4
1763
by: lkrubner | last post by:
I'm reading an essay, I think one of Crockford's, and it has this example in it: function Demo() { } Demo.prototype = new Ancestor(); Demo.prototype.foo = function () { } ; Does Ancestor now have a function called foo? What if I have 5 different objects, all descended from Ancestor? Do
13
2551
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
5
2230
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
2
2384
by: mithaelin | last post by:
ok, I can't get out of this riddle and Google seems can't help me. The problem is that this code doesn't work in iexplorer while it's perfect in other browser (didn't check in safari): <html> <head> <script src="include/js/scriptaculous/lib/prototype.js"></script> <script src="include/js/scriptaculous/src/scriptaculous.js"></script> <script type="application/javascript" language="javascript"> function goofy(id) { var linkList =...
2
1699
by: jidixuelang | last post by:
As I know,it's not well to extend Object.prototype derictly. In the Prototype(JS Framewoke),there is no extend Object.prototype. It only add some static method for Object class. I want to konw the reason.Who can give me some advise!?
2
2509
by: holtmann | last post by:
Hi, I got a question regarding JSON as datasource- I understand that eval on a JSON String creates the appropriate objects in JS. But I would like to use JSON to supply data to already defined prototpye objects. I try to give an example. I e.g. got: address.prototype = { firstname: null;
2
6457
by: hzgt9b | last post by:
I know how to overwrite a function. Normally this is what I would do: function someFunction() { /* orig definition here */ } //later in the execution stream I would do... someFunction = function () { /* overwrite function definition */ } The above works fine for me even when someFunction is originally defined in a seperate frame other than the code that overwrites it (obviously on the same domain). What I don't know how to-do is...
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.