Skip to main content

Bug Tracker

Side navigation

#262 closed bug (invalid)

Opened October 10, 2006 03:08AM UTC

Closed November 10, 2006 10:08AM UTC

Last modified February 20, 2011 09:41AM UTC

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

Reported by: Owned by:
Priority: major Milestone: 1.0
Component: core Version: 1.0a
Keywords: Cc:
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.

Attachments (0)
Change History (10)

Changed October 10, 2006 05:39AM UTC by anonymous comment:1

version: → 1.0b1

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

Changed October 10, 2006 12:34PM UTC by brandon comment:2

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

Changed October 16, 2006 09:32AM UTC by joern comment:3

resolution: → worksforme
status: newclosed

Changed November 09, 2006 06:28PM UTC by anonymous comment:4

cc: →
resolution: worksforme
status: closedreopened

Changed November 09, 2006 06:32PM UTC by dossy@panopt comment:5

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.

Changed November 09, 2006 07:05PM UTC by dossy@panopt comment:6

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, 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.hover(), jQuery.focus() and jQuery.blur() aren't functions any more, but jQuery.bind('{click,hover,focus,blur}', function) work as expected.

Changed November 10, 2006 12:22AM UTC by Michael Gear comment:7

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!

Changed November 10, 2006 10:08AM UTC by joern comment:8

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.

Changed January 17, 2007 05:01PM UTC by anonymous comment:9

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!!

Changed February 20, 2011 09:41AM UTC by shehriyari comment:10

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
	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?