Created
November 11, 2018 21:23
-
-
Save tondrej/193fd399d640b9e01dd4c717bc04bf44 to your computer and use it in GitHub Desktop.
Rectangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
TRectangle = class(TNativeObject) | |
class procedure InitializeInstance(AInstance: JsValueRef; Args: PJsValueRef; ArgCount: Word); override; | |
class function InitializePrototype(AConstructor: JsValueRef): JsValueRef; override; | |
end; | |
class procedure TRectangle.InitializeInstance(AInstance: JsValueRef; Args: PJsValueRef; ArgCount: Word); | |
var | |
ArgsArray: PJsValueRefArray absolute Args; | |
ShapeCtr: JsValueRef; | |
begin | |
// Shape.call(x, y); | |
ShapeCtr := JsGetProperty(JsGlobal, 'Shape'); | |
JsCallFunction(ShapeCtr, [AInstance, ArgsArray^[0], ArgsArray^[1]]); | |
// this.w = w; | |
JsSetProperty(AInstance, UnicodeString('w'), ArgsArray^[2]); | |
// this.h = h; | |
JsSetProperty(AInstance, UnicodeString('h'), ArgsArray^[3]); | |
end; | |
class function TRectangle.InitializePrototype(AConstructor: JsValueRef): JsValueRef; | |
var | |
ShapeCtr, ShapePrototype: JsValueRef; | |
begin | |
ShapeCtr := JsGetProperty(JsGlobal, 'Shape'); | |
ShapePrototype := JsGetProperty(ShapeCtr, 'prototype'); | |
// Rectangle.prototype = Object.create(Shape.prototype); | |
Result := JsCreateObject(ShapePrototype); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment