Closed Bug 1334608 Opened 7 years ago Closed 7 years ago

Firefox incorrectly reporting TypeError for JavaScript constructor followed immediately by cascading method calls

Categories

(Firefox :: Untriaged, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: nadams, Unassigned)

Details

Attachments

(2 files, 1 obsolete file)

162 bytes, text/html
Details
2.66 KB, application/javascript
Details
Attached file validconstructor.js (obsolete) —
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0
Build ID: 20161209095719

Steps to reproduce:

Load the HTML below and view the developer tools (Tools --> Web Developer --> Toggle Tools).

<html>
    <head>
        <title>Cascading constructor bug</title>
    </head>
    <body>
        <script src="validconstructor.js"></script>
    </body>
</html>



Actual results:

The associated JavaScript fails on line 111 of the attached js file.


Expected results:

Firefox should have recognized Cat2 as a constructor.

See lines 109-110 in the attached JavaScript file for more details.
Attached file constructorbug.html
Attached file validconstructor.js
Attachment #8831261 - Attachment is obsolete: true
Cat2 is undefined because Function.prototype.method returns undefined.

>     Function.prototype.method = function (name, func) {
>         if(!this.prototype[name]) {
>             this.prototype[name] = func;
>             return this;
>         }
>     };

method('get_name', ...) doesn't define "get_name" method, but does nothing and returns undefined,
since this.prototype[name] returns the following function:

> Mammal.prototype.get_name = function ( ) {
>     return this.name;
> };
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
Version: 50 Branch → unspecified
Please excuse my confusion, but if that be the case, then why do those functions work as expected by simply not cascading the method calls (replaces lines 91-92 with lines 93-94)?

Like so:

Replace:

}
    .inherits(Mammal)
//};
//Cat2.inherits(Mammal)

With:

//}
//    .inherits(Mammal)
};
Cat2.inherits(Mammal)
when you do |x = obj.f1().f2()|, x becomes the return value of f2,
when you do |x = obj; x.f1().f2()|, x becomes obj.
they're totally different code.

x becomes same thing only if f2 returns obj, but it doesn't on your case.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: