Comments (4)
property getter can be done by some trick
def property(f):
def empty():pass
ref = f('init')
attr = f.name
ref.prototype['_$'+attr] = ref.prototype[attr]
ref.prototype.__defineSetter__(attr,empty)
ref.prototype.__defineGetter__(attr,ref.prototype['_$'+attr])
class Test
def __init__(self):
self.data = [1,2,3,4,5]
@property
def __length__(self,init):
if init:return ABC
else: return len(self.data)
a = Test()
a.__length__ # output: 5
from rapydscript.
I wish I had more time to look at this, will leave alone for now but would appreciate if someone else could look into tackling this to handle these in pythonic way. Another good alternative for creating these is defineProperty function:
from rapydscript.
Implemented in my fork: kovidgoyal/rapydscript-ng@e9a6bd3
from rapydscript.
Implemented in ES6 mode with standard ES6 syntax (this is closest to variant 1 described above):
class Element:
def __init__(self, tag, attrib):
self._children = []
get length(self):
return len(self._children)
Still on the fence about implementing the Python syntax. While this is not standard Python approach (doesn't look like Python community is fond of them: http://stackoverflow.com/questions/2627002/whats-the-pythonic-way-to-use-getters-and-setters), the get/set
of ES6 seem to complement def
better.
from rapydscript.
Related Issues (20)
- append method does not compile to js push method HOT 1
- VSCode extension for syntax highlighting HOT 4
- cannot compare string HOT 3
- Typescript has problem compile RS --es6 output at class attributes HOT 2
- Why not support in-browser compiler? HOT 2
- enhancement: check for already reserved words like: enum HOT 18
- Cannot resolve python imports HOT 8
- Is that possible to parse python code to js AST? HOT 1
- fstring support. HOT 1
- How to keep all comments HOT 8
- Can't find python module that is installed and available? HOT 1
- Cannot catch ImportError HOT 2
- Cannot import from custom module in different directory HOT 5
- How to use RapydScript with JavaScript MutationObserver HOT 1
- Question about feasibility: option to use JS function syntax for nested functions, especially inside dicts/object-literals HOT 7
- How to run code snippets from tutorials on old Android? HOT 1
- Computed and negative slices
- parenthesized syntax HOT 2
- TypeError: undefined is not a function HOT 1
- Compiler issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rapydscript.