Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Oldes is right, the JS-like prototyping is not present in REBOL by default. But you are free to create own functionality that suits your needs. Here is simple example that uses nested context for value sharing between multiple instances to simulate the JS prototyping:</p> <pre><code>creature: func [ /prototype field [word!] value [any-type!] /local result proto ][ proto: [ context [ static: context [ vars: reduce [ 'kind "Monkey" ] extend: func [ blk [block!] field [word!] value [any-type!] /local pos ][ either pos: find/skip blk field 2 [ change/only next pos :value ][ insert/only insert tail blk reduce field :value ] :value ] get: func [ field [word!] ][ all [ field: any [ select/skip this/instance field 2 select/skip vars field 2 ] first field ] ] set: func [ field [word!] value [any-type!] ][ extend this/instance field :value ] prototype: func [ field [word!] value [any-type!] ][ extend vars field :value ] who-are-you: does [ print ["Hello I'm" this/get 'kind this/get 'sex this/get 'first-name join this/get 'last-name "."] ] ] instance: reduce [ 'first-name none 'last-name none ] ;exported "API" get: system/words/get in static 'get set: system/words/get in static 'set prototype: system/words/get in static 'prototype who-are-you: system/words/get in static 'who-are-you this: none ] ] unless object? proto/1 [result: reduce proto append clear proto result] if prototype [proto/1/prototype field :value] result: make proto/1 [] result/this: result ] creature/prototype 'sex "male" jane: make creature [] jane/set 'first-name "Jane" jane/set 'last-name "Rebol" john: make creature [] john/set 'first-name "John" john/set 'last-name "Doe" jane/who-are-you jane/set 'sex "female" jane/who-are-you john/who-are-you creature/prototype 'kind "Human" jane/who-are-you john/who-are-you </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload