WebReflection
Member since Apr 2015 • Last active May 2015Most recent activity
-
- 1 comment
- 2,686 views
-
-
As temporary work around on top of your file:
Function.bind||(Function.prototype.bind=function(c){var f=this,a=[].slice.call(arguments,1);return function(){a.push.apply(a,arguments);return f.apply(c,a)}});
In case you don't care about handling extra arguments ...
Function.bind||(Function.prototype.bind=function(c,f){f=this;return function(){return f.apply(c,arguments)}});
Until it's solved, of course
-
P.S. you've probably checked it already, but this would be already a great thing to have.
It's MIT Style License, it's deployed in micro controllers, and it's a subset for RegExp, a 1.5 subset.
It's called ure: http://docs.micropython.org/en/latest/library/ure.html#module-ure
Here the module used in micro python:
https://github.com/micropython/micropython/blob/a86d40ccd437fe0235c09426ef6d552b968d86e8/extmod/modure.cand here the folder with the lib:
https://github.com/micropython/micropython/tree/a86d40ccd437fe0235c09426ef6d552b968d86e8/extmod/re1.5 -
what you're trying to do on Espruino where you need this?
You have, as example, an opened bug about a comment weird behavior where the user coded via ES3 regular "classes" ... that code contains syntax usable since about ever and it would work everywhere.
I have a simple little module that brings better looking and more semantic classes in and when you deal with hardware you might want to use these patterns too (like the other user did).
Accordingly, having
instanceof
not working as expected is surprising and inconsistent, while I agreepropsrtyIsEnumerable
is a less common method that won't bring much in here.The missing RegExp should at least be mentioned on top of Espruino capabilities (if not already, couldn't find it) ... I often give them for granted, so I might lazily check
/something/.test(command)
instead ofcommand.indexOf(something) > 0
and for cross platform modules is very good to know limit.About that, I wonder what's the process to submit a module to the list of already available one in espruino, in case a working NPM solution would take long time.
Thank you
-
I wouldn't expect
toLocaleString
to be part of theObject.prototype
since there's no local in Espruino, but I found it weirdpropertyIsEnumerable
andisPrototypeOf
are not implemented.A quick and dirty solution would be the following:
Object.prototype.propertyIsEnumerable=function(p){for(var k in this)if(k==p)return this.hasOwnProperty(k);return false}; Object.prototype.isPrototypeOf=function(o){return o instanceof this.constructor};
However,
instanceof
is also broken in Espruino. Above code uses theconstructor
but a proper check would be the equivalent of the following:Object.prototype.isPrototypeOf=function(o){ function F() {} F.prototype = this; return o instanceof F; }; // this should be true Object.prototype.isPrototypeOf({});
Latter check is false but it should be true. Ideally,
isPrototypeOf
andpropertyIsEnumerable
should be implemented natively.Last question for now, I'v enoticed that
RegExp
and in general regular expression /syntax/ is not implemented. Is that too big to bring in natively or it's something planned already?Thanks
-
In fact I think even prefixing your module with var module=this; will work.
watch out, the
this
inside a module is theexports
itself, not the module ... I know it's quite confusing but better knowing this before doing any work.console.log(this === module.exports);
If you require a file like that, the log is
true
in (node|io).js
I've just dropped some RegExp check and polyfilled internally what was missing in Espruino, in case you'd like to have ES6 alike syntax for classes, with ES7 ability to compose through mixins/traits, I'd like to link you at this project of mine, called es-class
The minified version is not hand crafted/compacted explicitly for Espruino, but with plain 3.5kB (1.6kB gzipped) you get granted cross platform compatibility, including the MIPS node version of Arduino Yun, and basically all other JS engines out there I could verify.
Key features are:
Class({..})
declarationextends
and handythis.super(...)
abilitystatic
properties definitionswith: [ ... ]
plusimplements
for light checks on expected interfacesAs Gordon asked me in another thread, you ain't gonna need probably all these features, but maybe you'd like to write some code that looks like modern JS without breaking your Espruino.
Performance are also as good as vanilla JS, only light overhead is classes definitions, luckily this happens only once at bootstrap so you won't probably notice that.
All tests are green except those based on ES3 non standard get/set literal objects syntax which is not implemented here, and some tiny
instanceof
gotcha that will hopefully be solved soon since Gordon has already a bug to work on.I hope someone will find it handy.
Best Regards