Anonymous functions JS

Are anonymous functions a good solution to protect client-side logic ?

(function() {
// Am I safe here?
})()


>pic no related

Other urls found in this thread:

softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design
twitter.com/NSFWRedditImage

noob here
what are user functions

Function that get executed instantly, everything within that function should in theory be private so no other script can access what's in this function

Wtf do you mean "protect client side logic"?

2nd

Also you can pass parent's variables to child anonymous functions like this

(function ($) {
$('body').hide()
})(jQuery)

Don't really know, I've read that anonymous functions are safer on the front end and I just want to know why

why not make all the logic server side and what is the point of user functions?

noob here
what are children

Client side logic server side ?
Why?

noob here
what is client-side logic

Something you'll sadly never know

You cannot protect client-side logic. Don't bother trying.

I'm assuming you're making a game. Isn't that good for online games?

Samefagging

Nothing is safe on the front-end, friendo.

no, they can help prevent the use of global variables however

Functions that shitpost a lot. Still more bearable than trip functions though.

noob here
what is a noob

This and also the only way to try to "protect" the frontend code is using minification and obfuscation of the JS files, any code in the client side is always accesible to the users so don't handle sensitive information just validate and send the data to the server and validate again there

>Front end
>Safe

What the fuck am I reading in the pic?

>the only way to try to "protect" the frontend code
There is literally no safe client code.
The client can simply say "no" to your code and execute its own.

That is in fact an anonymous function because it has no name defined in the signature, but the real name is IIFE (immediately-invoked function expression). Also you may want to use modules and namespaces in your clients just as good practice

I know that is why I wrote "protect". No client code is safe

That's an iife,
you could do the same with a named function.

(function main(global) {

})(window) // runs instantly

main() // also works

A retarded lulzcow tranny running for senate doesn't know how gravity works

Ah, fuck my reading comprehension.

Anything in javascript except node.js basically

But that would execute only once when the compiler reads it the second will not be defined and throw an exception

>compiler

javascript is an interpreted language

Educate yourself swine
softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design

It depends on the implementation

Nothing on the front end is ever truly safe, anonymous functions can however make your code more unreadable, making it harder to determine what's going on in it.

The reason to use anonymous functions in the manner you have shown is to keep variable names from polluting the global namespace. It has nothing to do with "protecting" client side code.

If you are trying to protect trade secrets, the best you can do is an obfuscater, though a determined hacker will still find a way around that.

If you are trying to prevent cheating in browser-based video games, the only way to accomplish this is by using server-side verification of player actions. You +should operate under the assumption that the player is using a hacked client.

>execute only once when the compiler reads it
the compiler doesnt execute anything

No.
And you should always make your back-end code as safe as possible.
>tfw pizzeria site accepts any price from front-end (since you could customize the pizza)
Best free pizza of my life.

Also, what the fuck is Brianna Wu smoking?

>Rocks dropped from there have power of 100s of nuclear bombs
If you were on the surface of the moon and threw a rock at the Earth, the rock would come down and hit you on the head, because the gravitational pull of the moon is stronger than that of the Earth on the moon's surface (Earth too distant). Moreover, even if you were to eliminate the factor of the moon's gravity, you would need a rather big rock to fall into the Earth and not burn up in its atmosphere.

Not that the government hasn't toyed with the idea of dropping objects from space to kill people, but it would be from within the Earth's orbit, and it would be something a little bigger than a rock. Tungsten rods would be the ideal choice, due to their high density and heat resistance.

how to create massive memory leaks: the node.js way of programming

Nothing is safe in the frontend. Any information that you send to the front, you have to assume that you're practically handing it to the client. Cookies, web storage, whatever. If you have sensitive information that you want to keep a secret from the client, don't fucking send it to the client-side!

Assuming normal things, anything you type in that client-side-logic.js file is going to get sent to the client. You can put it through an obfuscator and a minifier and maybe it will be a little harder to read, but assume the client knows exactly what you're doing and how you do it when you're dealing in client-side javascript.

What's so special about your client-side logic anyway?

You better not be doing any kind of validation or password hashing in the browser.

The safer your program, the more replaceable your job.

Oh, and I should add: encoding things in base64 twice is not a valid way of hiding data from the client.

If you want to protect '''client side''' logic in JS
kill yourself

You cannot protect client-side logic. The client is untrusted. The client and and will fully access anything you send them.

pretty sure the guy who says noob here is the same guy not the other one who asked. Faggot

no

I know you're telling Javascript doesn't HAVE to be interpreted (like how C doesn't HAVE to be compiled), but I have yet to see a widely-used Javascript compiler.

/ourguy/ Terry Davis has a C (holyC) repl-type-thing

Who wants to make a JS compiler?

I'm not arguing that, I think Terry's just in time HolyC compiler is very nice.

I was making fun of for talking about a compiler when discussing JS shit.

Definitely a idiot.
But there would be still a advantage, since you could use smaller rockets to hit targets on earth from the moon, than starting rockets form Earth's orbit.
The cost of getting rockets to the moon would be ridiculous, so the best solution would be to produce them there in a moon base. Sounds like Iron Sky.

Launching missiles from the moon could have its advantages... were it not for the outer space treaty.

no you retard.

It's not going to execute unless you run it through a javascript interpreter. Scrapers will get your shit.

FUCKING RETARD

No, it's not. An anonymous function is an un-named function. What you're describing is a self executing function.