Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <| in this code mean?

function foo() {} var bar = foo <| function() {}; 

This is the first time I've seen something like this. What does <| mean?

Source: https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp1.js

like image 847
David G Avatar asked Aug 26 '11 17:08

David G


People also ask

What does :: mean in programming?

In C++, scope resolution operator is ::. It is used for following purposes. 1) To access a global variable when there is a local variable with same name: // C++ program to show that we can access a global variable. // using scope resolution operator :: when there is a local.

What do symbols mean in coding?

A symbol in computer programming is a primitive data type whose instances have a unique human-readable form. Symbols can be used as identifiers. In some programming languages, they are called atoms. Uniqueness is enforced by holding them in a symbol table.

What does </> mean in coding?

Generally speaking … it doesn't mean anything. It's become a symbolic representation of the culture of programming and software development for some people. Some people really like it.

What do u mean by code?

1 : a system of rules or principles a code of conduct. 2 : a system of signals or letters and symbols with special meanings used for sending messages. 3 : a collection of laws criminal code. 4 : genetic code. 5 : a set of instructions for a computer.


Video Answer


2 Answers

Now that you have posted the link to the source, you can see in the comments at the top of the file exactly what it does (line 36):

the <| operator -- defines the [[Prototype]] of a literal...

For these examples <| used with a function expression sets the [[Prototype]] of the object created as the value of the function's "prototype" property to the value of the "prototype" property of the the LHS object. This is in addition to setting the [[Prototype]] of the function object itself. In other words, it builds sets the [[Prototype]] of both the function and of function.prototype to potentially different values.

Update: I've just remembered this question as I came across the full ECMAScript Harmony proposal for this "literal [[Prototype]] operator". There is a lot more information in there than in the quote above, so it's worth a read.

like image 136
James Allardice Avatar answered Oct 04 '22 03:10

James Allardice


It looks like it should be

function foo() {} var bar = foo || function() {}; 

Which will assign foo to bar, if foo is defined and assign an empty function to bar otherwise.

About the link you posted later, it is still not valid Javascript. The project's README explains the purpose of the file.

This project contains example files of the various language extensions that are being considered for inclusion in the next editions of the ECMA Language Specification. The purpose of examples is to test the utility, writability, and readability of proposed features. There is no guarentee that any of these will actually be incorporated into the language.

A description of the proposed functionality brackets the lines of code you pasted into your question.

the <| operator -- defines the [[Prototype]] of a literal  /* Quote that James posted */  function foo() {}; const bar = foo <| function() {};  Object.getPrototypeOf(bar)===foo; //true Object.getPrototypeOf(bar.prototype)===foo.prototype;  //true 
like image 39
Dennis Avatar answered Oct 04 '22 03:10

Dennis