Eirik Vullum: JavaScript Metaprogramming - ES6 Proxy Use and Abuse | JSConf Budapest 2017

preview_player
Показать описание

But what is it even? And why do I need it?

Let’s take a closer look at this metaprogramming feature with some useful, abuseful and just plain fun uses of ES6 Proxy.

Рекомендации по теме
Комментарии
Автор

I still think he should have gotten an applause for [Function: Undefined]!

sab
Автор

This talk is just marvellous! Clean explanation of core concepts backed by a real world use case. I wish I could attend this in person at the time

sohamparekh
Автор

Dear god don't let DSL and custom syntax become a trend in Javascript.

FredrikChristenson
Автор

Just something quick to add, I'm totally for using this to create observalbe objects! Especially when you're linking your objects directly to DOM manipulation or something.

raybbo
Автор

Safe Null is actually the first thing came to my mind, when I've seen proxies.

sobanya_
Автор

Great introduction to Proxy and Reflection! Thanks for talk and nice and clear examples!

ashmig
Автор

I fully understand Proxies now, thanks!
However, I don't quite understand how Proxies would support the readability and maintainability of your code. The developer would really have to document this well for this to work.

Binding your data client-side like this doesn't make sense to me either, I much rather have the server deliver the data to me when I really need it instead of delivering bulk data like this.

raybbo
Автор

Your "undefined proxy" would result in some very painfull debugging, as it hides the origin of the missing data and silences errors. Your program might not crash, but having "undefined" in every place of the UI is not exactly what I would call a win.

Maybe using your seatbelt() function to generate more useful errors and/or safeguard accessing undefined object properties would be much more helpful.

MartinOfSomeName
Автор

Thanks Eirik, Proxies now make sense to me.

abhaytalks
Автор

FragmentjJS uses Proxy for creating magical reactivity

kuhaniresti
Автор

Real question is as a frontend developer or as node developer do i really need it ?

codewithsheikh
Автор

Populate can be done with getter and setter. No need for proxy.
I love the second example 😍
And a little sad that we can't replace object prototype. It would have been really fun 😎🤣

FrancoisLecroart
Автор

Graph can be accomplished with properties (getters?) alone - not sure how it'd be in JavaScript, but here's how it'd be in python - with 2 versions (story-centric vs person-centric)

people = []
stories = []

class Person(object):
def __init__(self, name):
self.name = name
self.read = []
self.liked = []
self.authored = []

@property
def authored(self):
return [story for story in stories if self is story.author]

class Story(object):
def __init__(self, title, author):
self.title = title
self.author = author

@property
def liked_by(self):
return [person for person in people if self in person.liked]

@property
def read_by(self):
return [person for person in people if self in person.read]


class Story(object):
def __init__(self, title, author):
self.title = title
self.author = author
self.read_by = []
self.liked_by = []

class Person(object):
def __init__(self, name):
self.name = name

@property
def authored(self):
return [story for story in stories if self is story.author]

@property
def liked(self):
return [story for story in stories if self in story.liked_by]

@property
def read(self):
return [story for story in stories if self in story.read_by]

AinurEru
Автор

Please don’t use this in your code with a team unless you have great documentation for it.

shinobi