Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#262 closed bug (invalid)

Extending Object prototype breaks jQuery (was: "name.replace is not a function" in 1.0.3)

Reported by: [email protected] Owned by:
Priority: major Milestone: 1.0
Component: core Version: 1.0a
Keywords: Cc: [email protected]
Blocked by: Blocking:


name.replace is not a function jquery.js (line 705)

This is at the end of the attr function, and I get the error even when I don't actually use jQuery.

Change History (10)

comment:1 Changed 16 years ago by anonymous

Version: 1.0b1

Sorry, I should clarify: simply adding the file to a page causes the error. No $() necessary.

comment:2 Changed 16 years ago by brandon

Could you provide an example page? What browser was this in? I am not able to reproduce this error.

comment:3 Changed 16 years ago by joern

Resolution: worksforme
Status: newclosed

comment:4 Changed 16 years ago by anonymous

Cc: [email protected] added
Resolution: worksforme
Status: closedreopened

comment:5 Changed 16 years ago by [email protected]

This is still an issue with jQuery 1.0.3. When loading jQuery in a LiveJournal page, the error is generated.

The backtrace according to FireBug:

name.replace is not a function jquery.js (line 725) anonymous jquery.js (line 725) anonymous jquery.js (line 122) anonymous jquery.js (line 355) anonymous jquery.js (line 95) anonymous jquery.js (line 108) anonymous jquery.js (line 339) null jquery.js (line 1192)

I'm guessing this is a bad interaction between LiveJournal's "core.js" which looks very Prototype-ish and jQuery.

comment:6 Changed 16 years ago by [email protected]

Summary: "name.replace is not a function" in 1.0.2"name.replace is not a function" in 1.0.3

I have a feeling this might be the culprit (in http://www.livejournal.com/js/core.js), but I'm only guessing:

219 Object.prototype.extend( {
220  init: Function.stub,
221  destroy: Function.stub
222 } );

Could that be interfering with jQuery.init()? Specifically, I notice that jQuery.click(), jQuery.hover(), jQuery.focus() and jQuery.blur() aren't functions any more, but jQuery.bind('{click,hover,focus,blur}', function) work as expected.

comment:7 Changed 16 years ago by Michael Gear

Shame on Six Apart. Nobody is allowed to extend Object.prototype. They are adding four methods: init, destroy, extend, and override. Take that code and shoot it!

comment:8 Changed 16 years ago by joern

Resolution: invalid
Status: reopenedclosed
Summary: "name.replace is not a function" in 1.0.3Extending Object prototype breaks jQuery (was: "name.replace is not a function" in 1.0.3)

It's nice to have compability with other's code, but this is a topic where we can't accound for bad coding style. Just as Mike proposed: Take and shoot it.

comment:9 Changed 16 years ago by anonymous

Sorry it this is of no help.... but I'll add it as it may help someone, somwhere.

I had the '.replace is not a function' error, and looked everywhere for a solution. But found none... After messing around for a while I found the solution.

My original code was:

var p = s.replace(/:/, '-');

it failed.

I changed it to:

s = s + ""; var p = s.replace(/:/, '-');

It appears the problem was 's' was not of type string, so JS assumed it must be a function call (but cannot find a function with that reference).

Perhaps this is related to this bug.... who knows!!

comment:10 Changed 12 years ago by shehriyari

So, even today when we are using jQuery v1.5, this problem still persists. Extending Object.prototype even from outside breaks it:

 * Object.isEmpty()
 * @returns {Boolean}
Object.prototype.isEmpty = function ()
	 * @deprecated Since Javascript 1.8.5
	 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object
	if ( this.__count__ !== undefined )
		return this.__count__ === 0 ? true : false;

	/* Less-aesthetic method, if above method fails */
	for ( var property in this )
		if ( this.hasOwnProperty(property) )
			return false;
	return true;

I am getting "c.replace is not a function" error :( . Can someone tell me why extending Object.prototype is bad coding, please?

Note: See TracTickets for help on using tickets.