Template literals evaluate to simple strings, there is no way to pass a
reference to an un-evaluated template literal. The function method is the
only way. Programmatically
```
String.substitute({ year: 2015}, `Last year was ${year-1}`);
```
is identical to
```
var str = `Last year was
let yearSentence = ({year:2015}=`This year is ${year}`)();
Enclosing the template string inside of a function is the way to go. Let's
call this one done.
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
@logan that's an interesting thought, which is why I posted this for
discussion, Thinking of that, I'm kind of doubting most will like the
function to only be able to take the literal instead as a variable because
that's just messing with the way Javascript itself.
Could be possible to pass a
Le 12 août 2015 à 15:41, Edwin Reynoso eor...@gmail.com a écrit :
Could we make the following possible, I can't seem to think of a way to do
it, since template literals are evaluated with the current scope, also tried
with `eval` but shouldn't even use that at all:
```JS
Could be possible to pass a string with instead of \`\`
At that point, you are implementing a templating language that happens to
match up syntactically with template literals. You'd also then be moving
parsing of the template to runtime instead of compile time, which will slow
things down.
AFAIK, this wont work because what clearTimeout() is actually expecting is
the id returned by setTimeout().
El 12/8/2015 16:00, Nick Krempel ndkrem...@google.com escribió:
On 12 August 2015 at 02:56, Isiah Meadows isiahmead...@gmail.com wrote:
```js
let p = new Promise((resolve, reject) =
```
function substitute(obj, str) {
return str.replace(/\${([^}]*)}/g, (m, p) = obj[p]);
}
substitute({ year: 2015 }, 'This is year ${year}'); // === 'This is year
2015'
```
On Wed, Aug 12, 2015 at 4:42 PM, Nathaniel Higgins n...@nath.is wrote:
Am I being naive or could this just be written
With `String.substitute()` you'd still be able to evaluate expressions,
it's kind of like changing scope, or passing an object to use for scoped
variables, which is not possible:
```JS
substitute({ year: 2015 }, 'Last year was year ${year-1}'); // Will throw
an error
```
You can't evaluate with
Yes of course, still requires 1.Destructuring, and making a function for
each type of string to return. Defeats the purpose.
I'd have to make different functions for each template:
```JS
const yearTemplate = ({ year }) = `This year is ${year}`;
const ageTemplate = ({ age}) = `I'm ${age} yrs
Am I being naive or could this just be written in user space?
Sent from my iPhone
On 12 Aug 2015, at 15:31, Edwin Reynoso eor...@gmail.com wrote:
Yes of course, still requires 1.Destructuring, and making a function for each
type of string to return. Defeats the purpose.
I'd have to
This was assuming an API like addEventListener/removeEventListener, not the
standard DOM setTimeout/clearTimeout, sorry for the confusion.
On 12 August 2015 at 15:46, Salvador de la Puente González
sa...@unoyunodiez.com wrote:
AFAIK, this wont work because what clearTimeout() is actually
On Wed, Aug 12, 2015 at 7:31 AM, Edwin Reynoso eor...@gmail.com wrote:
Yes of course, still requires 1.Destructuring, and making a function for
each type of string to return. Defeats the purpose.
I'd have to make different functions for each template:
```JS
const yearTemplate = ({ year }) =
Yes I'm aware @claude that its kind of like the `with` statement
@Logan instead it would allow a way for a developer to parse the template
on call.
What's wrong with that?
And also will allow me to not use **Handlebars** or **Mustache**
I don't see anything wrong with having a method to do
Oops... Used to Node world. I didn't really test it, since I replied by
phone.
On Wed, Aug 12, 2015, 10:46 Salvador de la Puente González
sa...@unoyunodiez.com wrote:
AFAIK, this wont work because what clearTimeout() is actually expecting is
the id returned by setTimeout().
El 12/8/2015
I can see why, since nearly everyone depends on that coupling. Minifiers
depend on it. Mixin utilities depend on it. Breaking the Web would be an
understatement.
On Wed, Aug 12, 2015, 14:36 Brendan Eich bren...@mozilla.org wrote:
Caitlin Potter wrote:
ES2015 already has element accessor
Oh. Pardon my ignorance. Misunderstood the idea.
On Wed, Aug 12, 2015, 23:19 Allen Wirfs-Brock al...@wirfs-brock.com wrote:
On Aug 12, 2015, at 7:30 PM, Isiah Meadows wrote:
I can see why, since nearly everyone depends on that coupling. Minifiers
depend on it. Mixin utilities depend on it.
For use cases that require named Functions (e.g. recursion), surely it's
not a such a big deal to either assign an Array Function to a variable
first, or use the good old trusty named Function expression or Function
statement.
var recurseExample = () = { recurseExample(); }
var recurseExample =
Ups, I answered only to Jacob but I think this is a real simple solution:
var factorial;
x.map(factorial = x = x 1 ? 1 : x * factorial(x-1));
Or simply:
var factorial = x = x 1 ? 1 : x * factorial(x-1);
x.map(factorial);
As you said, this is ocassionally needed. And for
Le 12 août 2015 à 17:35, Edwin Reynoso eor...@gmail.com a écrit :
(...) and this discussion led me to know that this could allow a way to
interact with the parser on call, which IMO could be useful.
JavaScript has already a built-in feature for interacting with the parser at
runtime:
Oh, forgot to add a bit to those snippets to divide the bytes_per_element into
bits, but yeah
On Aug 11, 2015, at 2:55 PM, Michael McGlothlin mike.mcgloth...@gmail.com
wrote:
SIMD types appear almost as limited in size as using numbers. Often I need to
manipulate thousands or millions of
Well, you could just use typed arrays for this, and add a helper function which
retrieves the bit at a specific index. Like, something like this:
```
function bitset_get(ta, i) {
var e = (i / ta.BYTES_PER_ELEMENT) | 0;
i = i % ta.BYTES_PER_ELEMENT;
return (ta[e] i) 1;
}
```
You could
Le 12 août 2015 à 15:41, Edwin Reynoso eor...@gmail.com a écrit :
Could we make the following possible, I can't seem to think of a way to do
it, since template literals are evaluated with the current scope, also tried
with `eval` but shouldn't even use that at all:
```JS
On 12 August 2015 at 02:56, Isiah Meadows isiahmead...@gmail.com wrote:
```js
let p = new Promise((resolve, reject) =
setTimeout((x = () = x(x))(handler = {
onNotNeeded(() = clearTimeout(handler));
// `return` is to take advantage of TCO
return doSomethingAsync(err = {
Could we make the following possible, I can't seem to think of a way to do
it, since template literals are evaluated with the current scope, also
tried with `eval` but shouldn't even use that at all:
```JS
String.substitute( { year: 2015 }, `This year is ${year}` ); // Returns
This year is 2015
ES2015 already has element accessor overloading with proxies, right?
It's everything else that's missing.
Proxies enforce invariants, which is problematic for this use case because it’s
A) expensive, and B) also restricts you from “lying” about the actual
properties which exist on the
On Wed, Aug 12, 2015 at 4:50 AM, Caitlin Potter caitpotte...@gmail.com wrote:
Operator overloading or value types might make it look a lot prettier some
day (though iirc element assessor overloading was off limits), but you could
get pretty far by baking it into a compile-to-js language.
Also `instanceof` overloading via `Symbol.hasInstance`
On Wed, Aug 12, 2015 at 10:44 AM, Daniel Ehrenberg dehrenb...@chromium.org
wrote:
On Wed, Aug 12, 2015 at 4:50 AM, Caitlin Potter caitpotte...@gmail.com
wrote:
Operator overloading or value types might make it look a lot prettier
some
27 matches
Mail list logo