Why does this not work:function foo() {
this.bar = function() {
console.log('a');
};
}
foo.bar(); // TypeError: Cannot find function bar in object function foo() {...}
And this works:function foo() {}
foo.bar = function() {
console.log('b');
};
foo.bar(); // prints b
>>58837624
>javascript
that's why
Can we just like... ban Javascript or something?
u need to call the contructor function to use this.foo
var baz = new foo();
baz.bar();
also you should put your funcion in a var
the first one:
"have a function foo, that, when called, sets this.bar to something"
you're not calling the function, so foo.bar can't exist
the second one:
"define function foo, define foo.bar"
these are separate steps that are executed immediately
>>58837624
If you couldn't figure that out, programming is not for you
>javascript
>>58837700
What the fuck did you just fucking type about me, you little bitch? I’ll have you know I graduated top of my class at MIT, and I’ve been involved in numerous secret raids with Anonymous, and I have over 300 confirmed DDoSes. I am trained in online trolling and I’m the top hacker in the entire world. You are nothing to me but just another virus host. I will wipe you the fuck out with precision the likes of which has never been seen before on the Internet, mark my fucking words. You think you can get away with typing that shit to me over the Internet? Think again, fucker. As we chat over IRC I am tracing your IP with my damn bare hands so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your computer. You’re fucking dead, kid. I can be anywhere, anytime, and I can hack into your files in over seven hundred ways, and that’s just with my bare hands. Not only am I extensively trained in hacking, but I have access to the entire arsenal of every piece of malware ever created and I will use it to its full extent to wipe your miserable ass off the face of the world wide web, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking fingers. But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit code all over you and you will drown in it. You’re fucking dead, kiddo.
>>58837679
wrong, bar is the function, not the result of its call. the problem comes from not using new
>>58837624
What the world needs is this. It's not catching up because the web dev industry is filled with bootcamp retards who fall for the latest JS framework fad.