Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function-declarations and recursive #53

Open
boris-42 opened this issue Mar 28, 2012 · 1 comment
Open

function-declarations and recursive #53

boris-42 opened this issue Mar 28, 2012 · 1 comment

Comments

@boris-42
Copy link

// named function expression
/* Benefits:
* 1. Provides the debugger with an explicit function name: helps stack inspection.
* 2. Allows recursive functions: getData can call itself.
* Issues:
* 1. there are historic quirks with IE
*/
var getData = function getData () {
};

This is very bad idea. We have already possibility for recursion in previous both examples.

While all functions (absolutly annonimus also) can call itself using arguments.callee.

For Example:

var some = function(a){
if(a == 0 || a == 1)
return 1;

var t = arguments.callee; 
return  t(a-1) + t(a-2);  

}
alert(some(5));

@devinrhode2
Copy link
Contributor

I believe in strict mode, arguments.callee is no longer going to be available, precisely because functions should be named. As I understood it, this was a bad idea for security reasons, and is being pushed back.

On the same note of function declarations... I'm think we should consider a naming pattern when you are adding a function as a property within another object. Consider this code:

var api = {};
api.someFunction = function apiSomeFunction("?") {
  //do I recurse with api.someFunction() or apiSomeFunction()?
  //Both work, which raises the question, is there ever a scenario a which api.someFunction
    *won't be defined at the point it gets called*?
};

Lastly, I think we should establish the naming convention above, where functions as properties of other objects are camelCased from obj.subFunction to either subFunction or, objSubFunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants