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. 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;
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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:
|
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
|
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
|
by: Daz |
last post by:
Hi everyone.
My query is very straight forward (I think).
What's the difference between
someFunc.blah = function(){ ; }
and
| |
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 =...
|
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!?
|
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;
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| | |