delete in js

The delete operator removes a property from an object.

delete is only effective on an object’s properties. It has no effect on variable or function names.

If the object inherits a property from a prototype, and doesn’t have the property itself, the property can’t be deleted by referencing the object. You can, however, delete it directly on the prototype.

function Foo(){} = 42;
var foo = new Foo();

// returns true, but with no effect, 
// since bar is an inherited property

// logs 42, property still inherited

// deletes property on prototype

// logs "undefined", property no longer inherited

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s