News for hackers. Stuff that matters.
Re:Meta-programming JavaScript Using Proxies by krzbrg on Thursday February 05, 2015 @11:08AM (#9003927)
It was odd that the post was prefaced with a warning that "you will have to use Chrome/Chromium" before opening with an example copied and pasted from Mozilla's docs. This is not true. The example works in the Firefox 35.0.1 console out of the box. There are no feature flags or internal browser configurations that need to be changed. Also worth noting that the first example came from an outdated MDN Proxy API documentation page [1]. The current Proxy API page covers the ECMAScript 6 proposal [2].

If you're interested in seeing which browsers have implemented these ES6 features, Kangax has a nice table up on GitHub pages [3].

[1] https://developer.mozilla.org/en-US/docs/Archive/Web/Old_Pro...

[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[3] http://kangax.github.io/compat-table/es6/

Re:Meta-programming JavaScript Using Proxies by epidemian on Thursday February 05, 2015 @12:45PM (#9004613)
Not only that, but Proxy has been implemented in Firefox for a while†. I remember having played with it a long time ago.

†: Since Firefox 18 according to the MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...

Re:Meta-programming JavaScript Using Proxies by donatj on Thursday February 05, 2015 @07:52AM (#9002938)
Having seen this kind of "magic" as PHP calls it, come full force and then largely leave in the PHP ecosystem after we became tired of it, I can't say I miss it.

It's fun to play with but for actual work a clear, strongly defined API beats this sort of syntactic sugar like this any day.

Re:Meta-programming JavaScript Using Proxies by kbody on Thursday February 05, 2015 @08:40AM (#9003150)
Quite true, I rather leave magic at Hogwarts. Although the package nature of node etc. could be fitting for such magic behind some public facing API.

Also, I have some concerns over their performance but we will see in time.

Re:Meta-programming JavaScript Using Proxies by sklogic on Thursday February 05, 2015 @09:22AM (#9003337)
Because neither PHP nor JS can do anything close to a proper metaprogramming. No API can compete with a properly designed eDSL.
Re:Meta-programming JavaScript Using Proxies by mistercow on Thursday February 05, 2015 @10:21AM (#9003619)
Drawing a line around one kind of metaprogramming and calling it "proper" is pretty silly.
Re:Meta-programming JavaScript Using Proxies by sklogic on Thursday February 05, 2015 @12:32PM (#9004532)
By "proper" I mean everything that is opposite to the "bad" kind of metaprogramming people shun upon (C-preprocessor-style).
Re:Meta-programming JavaScript Using Proxies by dracolytch on Thursday February 05, 2015 @08:18AM (#9003042)
I'm not really sure changing the behavior of fundamental operations really counts as metaprogramming, but in many ways I think it's very in-line with some conceptual constructs JS already has in place. Considering that you can access an object's properties by addressing an array, the ability to call a function by accessing a property isn't very alien. Considering the flexibility of JS, I'd be curious to see how crazy you could get.

At the same time, I'm also very scared to see what kind of crazy code this will lead to that I'd have to look at. I think lots of people will probably implement overly complex or obtuse ideas because they are interesting.

Re:Meta-programming JavaScript Using Proxies by rrubmo on Thursday February 05, 2015 @08:42AM (#9003164)
I was the only one playing with the cover effect for about 5 min?
Re:Meta-programming JavaScript Using Proxies by JackuB on Thursday February 05, 2015 @10:34AM (#9003719)
Saw it used on other sites too.

Here is original: http://tympanus.net/Development/AnimatedHeaderBackgrounds/

Re:Meta-programming JavaScript Using Proxies by bwheel on Thursday February 05, 2015 @10:01AM (#9003522)
+1
Re:Meta-programming JavaScript Using Proxies by xpop2027 on Thursday February 05, 2015 @09:07AM (#9003267)
Same boat
Re:Meta-programming JavaScript Using Proxies by z3t4 on Thursday February 05, 2015 @02:49PM (#9005495)
Have a look at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... http://kangax.github.io/compat-table/es5/#Object.definePrope...

I'm currently working on a data persistence module with database backend in Node.js using Object.defineProperty that define get and set.

Re:Meta-programming JavaScript Using Proxies by towelguy on Thursday February 05, 2015 @12:07PM (#9004365)
It's akin to python's magic methods (eg. __len__), only implemented in a separate object. Looks cleaner.
Re:Meta-programming JavaScript Using Proxies by davidchase03 on Thursday February 05, 2015 @09:02AM (#9003244)
Didn't they change the spec for Proxies and as of Chrome v40 Proxy doesnt exist in the devtools? I tried it in my Chrome/Canary and it wasn't there however it did work in Firefox v35
Re:Meta-programming JavaScript Using Proxies by domenicd on Thursday February 05, 2015 @02:22PM (#9005283)
We haven't started implementing proxies in V8. There was a prototype implementation of an old proposal but that's kind of dead code now.
Re:Meta-programming JavaScript Using Proxies by kaonashi on Thursday February 05, 2015 @02:26PM (#9005320)
Seems something like ruby's method_missing.
Re:Meta-programming JavaScript Using Proxies by james2vegas on Saturday February 07, 2015 @04:45PM (#9015414)
many languages that do OO have that; Perl, Smalltalk, Objective-C, f.e.. But this seems more like monkey-patching.
Re:Meta-programming JavaScript Using Proxies by benihana on Thursday February 05, 2015 @08:58AM (#9003231)
This article was initially baffling to me. There's no link to the API or libraries, or functions or whatever the hell the author is talking about, so since I'm not following all this stuff closely, I don't know if this is a proposed change to JavaScript or an external library or what.

So then I go here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... and realize that it's an experimental proprosal for ES6, which means it's going to be a while before I can even think about using this. Then I realize the MDN article actually explained proxies and what they're designed for way better than this article (they're meant as a functional hook when manipulating properties on an object). It has useful, non-contrived examples that illustrate better than this article why you'd want this in the spec.

Re:Meta-programming JavaScript Using Proxies by domenicd on Thursday February 05, 2015 @02:20PM (#9005269)
It's not an experimental proposal for ES6, it's part of ES6, which is now finalized as of our most recent TC39 meeting last week. (There will only be editorial fixes going forward.)

Regardless, it doesn't matter what language version it's in. What matters is that it's already implemented in Firefox and the IE previews.

Re:Meta-programming JavaScript Using Proxies by couchand on Thursday February 05, 2015 @08:15AM (#9003029)
These are some neat uses of ES6 Proxies, but I can't handle a typo as the very first word of the article.
Re:Meta-programming JavaScript Using Proxies by Bahamut on Thursday February 05, 2015 @11:47AM (#9004195)
Agreed, interesting that a typo so early has such a strong psychological effect.

The article could use some better structuring, but it does contain some interesting ideas for using proxies.

Re:Meta-programming JavaScript Using Proxies by krazydad on Thursday February 05, 2015 @01:48PM (#9005042)
Agreed. Giant cover image with pointless mouse-over effect immediately followed by typo on first word. Ugh.