javascript - Is there a way to declare functions in constructor? -


first of all, recognize there 100+ threads on method.this vs var method, etc. not asking. know differences. confused of function expressions vs function declarations in context of creating objects using constructor.

what wanted know this: how come function declarations never appear in constructors, function expressions do? whenever declare function rather use expression not accessible in object once initiated; why this?

i think because either local (aka private) , inaccessible, or when creating objects, if constructor not see function prefixed 'this', 'var', or 'constructor.prototype', skips it.

how come function declarations never appear in constructors, function expressions do?

they do

whenever declare function rather use expression not accessible in object once initiated; why this?

you must doing wrong.

  function thing() {     function go() {       alert('hello');     }     this.foo = 1;     this.bar = function () {       go();     }   }    var x = new thing();   x.bar(); 

i think because either local (aka private) , inaccessible

function declarations locally scoped. doesn't stop assigning them wider scope, object property or using them within scope declared within.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -