Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8572 closed bug (invalid)

jQuery.isPlainObject

Reported by: hidespb Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

Hi! here's some kinda of bug i've found a few days ago:

  1. Change Object's prototype:
    Object.prototype.somefunc = foo() {bar;}
    
  1. Try to create an element:
    var div = $('<div/>', {
    	class: 'someclass'
    });
    
  1. Browser throws an Exception:
    'TypeError: doc.createElement is not a function'
    

Reason for this exception is located at line 138:

if ( ret ) {
	if ( jQuery.isPlainObject( context ) ) {
		selector = [ document.createElement( ret[1] ) ];
		jQuery.fn.attr.call( selector, context, true );

	} else {
		selector = [ doc.createElement( ret[1] ) ];
	}

}

jQuery.isPlainObject return false on a object having it's prototype modified. In normal case jQuery should use document.createElement, but in case of abnormal return it uses doc.createElement instead.
p.s. sry for bad english

Change History (1)

comment:1 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

1) Don't modify Object.prototype because jQuery doesn't support pages that do this.

2) Don't use a bareword class for a property name because it is a JavaScript reserved word. Either quote the name or use className instead.

Note: See TracTickets for help on using tickets.