Does Rebol really have an equivalent for a javascript prototype property?

Greggi made a post about rebol and javascript here http://blog.revolucent.net/2009/05/javascript-rebol.html

But since I'm going to compare javascript and rebol more deeply, I don’t see what is equivalent to rebol for a javascript prototype. Since extending an instance of an object from another with make to rebol is not very similar to the javascript prototype property, because the js prototype allows ALL instances to be distributed at the same time.

I am mistaken or there is a code equivalent below for rebol:

<html>
<head>
</head>

<body>
  <script>        
    function Person(firstName, lastName, sex) {
      this.firstName = firstName;
      this.lastName = lastName;      
      this.whoAreYou = function() {
        alert( "I've been built with Constructor and my name is " + this.firstName + " " + this.lastName);
      }
      this.WhatIsYourSex = function() {
        alert(this.sex);
      }
    };

    Person.prototype.sex = "Man";

  </script>

  <script>
    JaneDoe = new Person("Jane", "Doe");
    JaneDoe.whoAreYou();
    JaneDoe.WhatIsYourSex();
    alert("Are you sure?");
    JaneDoe.sex = "Woman";
    JaneDoe.WhatIsYourSex();
  </script>

</body>
</html>

: , , . R2, . INSTANCE, : , js.

, : Rebol AUTOMATICALLY ALL INSTANCES , , javascript, , ?

R2 R3 , , , , , , . , jquery, ? .

+5
4

Oldes , JT- REBOL. , . , JS:

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
+7

REBOL .

R3 . , , . , , - .

REBOL 2, , ; , , , . , .

REBOL 3 . expand .


script : .

  • :
  • REBOL 2,
  • ,
+6

Rebol Tutorial, " ", ? , , - , , ?: -)

, - , , ? "... " .

:

obj: context [a: 1]   == ! [       a: 1   ]

     

dt loop 1'000'000 [append blk copy obj]   == 0: 00: 00.023372

     

? BLK   == 1000000

     

dt [foreach obj blk [append obj [b: 2]]]   == 0: 00: 02.677348

     

? BLK   == 1000000

     

BLK/1   == ! [       a: 1        2   ]

     

BLK/2   == ! [       a: 1        2   ]

     

blk/1/a: 3   == 3

     

BLK/1   == ! [       a: 3        2   ]

     

BLK/2   == ! [       a: 1        2   ]

, , 1 == 0: 00: 02.677348. 4- . ?

, , , , , , : -)

-pekr -

+3

, - :

person: context [
    firstName: secondName: none
    whoAreYou: does [print [firstName secondName]]
    WhatIsYourSex: does [print sex]
]
extend person 'sex "male"
JaneDoe: make person [firstName: "Jane" secondName: "Doe"]
JaneDoe/whoAreYou
JaneDoe/WhatIsYourSex
ask "Are you sure?"
JaneDoe/sex: "female"
JaneDoe/WhatIsYourSex

, , , . JS-.

, , :

<script>
    JaneDoe = new Person("Jane", "Doe");
    DoeJane = new Person("Doe", "Jane");
    Person.prototype.sex = "Man";
    JaneDoe.WhatIsYourSex();
    DoeJane.WhatIsYourSex();
</script>

Than I have to say that in REBOL something like this is not supported, at least for now.

+1
source

All Articles