JE::Undefined - JavaScript undefined value


JE documentation Contained in the JE distribution.

Index


Code Index:

NAME

Top

JE::Undefined - JavaScript undefined value

SYNOPSIS

Top

  use JE;

  $j = new JE;

  $js_undefined = $j->undef;

  $js_undefined->value; # undef

DESCRIPTION

Top

This class implements the JavaScript "undefined" type. There really isn't much to it.

Undefined stringifies to 'undefined', and is false as a boolean.

SEE ALSO

Top

JE::Types
JE::Null
JE

JE documentation Contained in the JE distribution.

package JE::Undefined;

our $VERSION = '0.54';

use strict;
use warnings;

use overload fallback => 1,
	'""' => 'typeof',
#	 cmp =>  sub { "$_[0]" cmp $_[1] },
	bool => \&value,
	'0+' =>  sub { sin 9**9**9 };

# ~~~ How should this numify?

require JE::String;
require JE::Boolean;


# A JE::Undefined object is a reference to a global object.

sub new    { bless \do{my $thing = $_[1]}, $_[0] }
sub value  { undef }
sub typeof { 'undefined' }
sub id     { 'undef' }
sub primitive { 1 }
sub to_primitive { $_[0] }
sub to_boolean   { JE::Boolean->new(${+shift}, 0) }
sub to_string { JE::String->_new(${+shift}, 'undefined') };
sub to_number { JE::Number->new(${+shift}, 'NaN') }
sub global { ${$_[0]} }

return "undef";
__END__