Javascript delete mechanics
javascript
Solution
`delete` only works on deleteable properties. Functions declared like this:
function f(){
}
are not deleteable.
Try using this syntax for the original function declaration:
foo = function (){var bar=0; return function(){return bar++;}}
See it here: http://jsfiddle.net/Sxnaw/
You can go through this article for an in depth explanation of deleteable and non deleteable properties: http://perfectionkills.com/understanding-delete/
Problem
Possible Duplicate: the delete operator in javascript I have the following code. I don't understand why the second delete fails. Also, I noticed that the foo function still exists even after I assigned something else to foo. Is there a way to reference the function? (suppose I'd want a `bar2=foo()` to behave like the `bar` assignment). ``` > function foo(){var bar=0; return function(){return bar++;}} undefined > bar = foo() function () {return bar++;} > bar() 0 > bar() 1 > delete bar true > foo = foo() function () {return bar++;} > foo() 0 > foo() 1 > delete foo false ``` Thanks