[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Anonymous functions JS

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 54
Thread images: 3

File: 1488983470041-g.jpg (50KB, 602x536px) Image search: [Google]
1488983470041-g.jpg
50KB, 602x536px
Are anonymous functions a good solution to protect client-side logic ?

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


>pic no related
>>
noob here
what are anon functions
>>
>>59367763
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
>>
>>59367744
Wtf do you mean "protect client side logic"?
>>
>>59367809
2nd
>>
>>59367763
Also you can pass parent's variables to child anonymous functions like this

(function ($) {
$('body').hide()
})(jQuery)
>>
>>59367809
Don't really know, I've read that anonymous functions are safer on the front end and I just want to know why
>>
>>59367805
why not make all the logic server side and what is the point of anon functions?
>>
>>59367850
noob here
what are children
>>
>>59367886
Client side logic server side ?
Why?
>>
>>59367809
noob here
what is client-side logic
>>
>>59367909
Something you'll sadly never know
>>
You cannot protect client-side logic. Don't bother trying.
>>
>>59367914
I'm assuming you're making a game. Isn't that good for online games?
>>
>>59367763
>>59367909
>>59367914
>>59367959
Samefagging
>>
>>59367866
Nothing is safe on the front-end, friendo.
>>
no, they can help prevent the use of global variables however
>>
>>59367763
Functions that shitpost a lot. Still more bearable than trip functions though.
>>
noob here
what is a noob
>>
>>59368993
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
>>
File: 1473282216704.jpg (60KB, 616x769px) Image search: [Google]
1473282216704.jpg
60KB, 616x769px
>>59367866
>Front end
>Safe
>>
>>59367744
What the fuck am I reading in the pic?
>>
>>59369292
>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.
>>
>>59367744
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
>>
>>59369363
I know that is why I wrote "protect". No client code is safe
>>
>>59367744
>>59367850

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

(function main(global) {

})(window) // runs instantly

main() // also works
>>
>>59369356
A retarded lulzcow tranny running for senate doesn't know how gravity works
>>
>>59369390
Ah, fuck my reading comprehension.
>>
>>59367931
Anything in javascript except node.js basically
>>
>>59369395
But that would execute only once when the compiler reads it the second will not be defined and throw an exception
>>
File: man laughing.jpg (6KB, 264x191px) Image search: [Google]
man laughing.jpg
6KB, 264x191px
>>59369535
>compiler
>>
>>59369535
javascript is an interpreted language
>>
>>59369549
Educate yourself swine
http://softwareengineering.stackexchange.com/questions/138521/is-javascript-interpreted-by-design
>>
>>59369580
It depends on the implementation
>>
>>59367744
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.
>>
>>59369612
>>59369594
>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.
>>
>>59367744
how to create massive memory leaks: the node.js way of programming
>>
>>59367744
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!
>>
>>59367744
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.
>>
>>59370216
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
>>
>>59367744
You cannot protect client-side logic. The client is untrusted. The client and and will fully access anything you send them.
>>
>>59367993
pretty sure the guy who says noob here is the same guy not the other one who asked. Faggot
>>
>>59369594
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.
>>
>>59370775
/ourguy/ Terry Davis has a C (holyC) repl-type-thing

Who wants to make a JS compiler?
>>
>>59370843
I'm not arguing that, I think Terry's just in time HolyC compiler is very nice.

I was making fun of >>59369594 for talking about a compiler when discussing JS shit.
>>
>>59369899
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.
>>
>>59371088

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
>>
>>59367805
No, it's not. An anonymous function is an un-named function. What you're describing is a self executing function.
Thread posts: 54
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.