class JSCObject::Accessor(T)

Overview

An Accessor represents a JavaScript object's property which is defined via JS Object.defineProperty An Accessor can define its own setter or getter via Accessor#get(&block) and Accessor#set(&block). An Accessor can have both setter and getter, either, or even none.

require "uuid"
uuid = JSCObject.new
uuid_get_only_accessor = JSCObject::Accessor(String).new name: "random"
uuid.get do
  UUID.random
end
uuid.mount_accessor uuid_get_only_accessor
JSCContext.set_value "UUID", uuid

In WebInspector, types UUID.random

Defined in:

components/jsc_object/accessor.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(name : String) #

Initializes a new Accessor, given it name.


[View source]

Instance Method Detail

def get(&block : -> T) #

Specifies Accessor's getter


[View source]
def set(&block : Proc(JSCFunction | JSCObject | JSCPrimative, Nil)) #

Specifies Accessor's setter.


[View source]