Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Correct statement about typeof/constructor/^name in JS nutshell
typeof has no equivalent in Perl 6. The constructor property has an
equivalent, but it's not the ^name meta-attribute, it's the WHAT
attribute.
  • Loading branch information
Kaiepi committed Mar 9, 2019
1 parent f70f13f commit fea4772
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions doc/Language/js-nutshell.pod6
Expand Up @@ -256,17 +256,15 @@ $str ~~ s/abc/def/; # Mutates $str, like foo.replace('abc', 'def')
say $str; # def
=end code
While we are talking about C<instanceof>, the equivalent to L<C<typeof>|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof> or the
C<constructor> property on Node.js objects in Perl 6 is the C<^name>
meta-attribute:
While we are talking about C<instanceof>, the equivalent to the C<constructor>
property on Node.js objects in Perl 6 is the C<WHAT> attribute:
=begin code :lang<javascript>
console.log(typeof 'foo'); // string
console.log('foo'.constructor); // String
console.log('foo'.constructor); // OUTPUT: String
=end code
=begin code
say 'foo'.^name; # Str
say 'foo'.WHAT; # OUTPUT: Str
=end code
=head3 Numeric
Expand Down Expand Up @@ -415,10 +413,10 @@ $client.print: 'Hello, world!';
my IO::Socket::INET $conn = $server.accept;
my Str $msg = $conn.recv;
say $msg; # RESULT: Hello, world!
say $msg; # OUTPUT: Hello, world!
$conn.print($msg);
say $client.recv; # RESULT: Hello, world!
say $client.recv; # OUTPUT: Hello, world!
$conn.close;
$client.close;
$server.close;
Expand All @@ -437,15 +435,15 @@ instead:
my $supply = IO::Socket::Async.listen('localhost', 8000);
my $server = $supply.tap(-> $conn {
$conn.Supply.tap(-> $data {
say $data; # RESULT: Hello, world!
say $data; # OUTPUT: Hello, world!
await $conn.print: $data;
$conn.close;
})
});
my $client = await IO::Socket::Async.connect('localhost', 8000);
$client.Supply.tap(-> $data {
say $data; # RESULT: Hello, world!
say $data; # OUTPUT: Hello, world!
$client.close;
$server.close;
});
Expand All @@ -461,7 +459,7 @@ const net = require('net');
const server = net.createServer(conn => {
conn.setEncoding('utf8');
conn.on('data', data => {
console.log(data); # RESULT: Hello, world!
console.log(data); # OUTPUT: Hello, world!
conn.write(data);
conn.end();
});
Expand All @@ -470,7 +468,7 @@ const server = net.createServer(conn => {
const client = net.createConnection(8000, 'localhost', () => {
client.setEncoding('utf8');
client.on('data', data => {
console.log(data); # RESULT: Hello, world!
console.log(data); # OUTPUT: Hello, world!
client.end();
server.close();
});
Expand Down

0 comments on commit fea4772

Please sign in to comment.