MCPcopy Create free account
hub / github.com/NativeScript/android / __extends

Function __extends

test-app/app/src/main/assets/internal/ts_helpers.js:50–106  ·  view source on GitHub ↗
(Child, Parent)

Source from the content-addressed store, hash-verified

48 };
49
50 var __extends = function (Child, Parent) {
51 var extendNativeClass = !!Parent.extend && (Parent.extend.toString().indexOf("[native code]") > -1);
52 if (!extendNativeClass) {
53 __extends_ts(Child, Parent);
54 return;
55 }
56 if (Parent.__isPrototypeImplementationObject) {
57 throw new Error("Can not extend an already extended native object.");
58 }
59
60 function extend(thiz) {
61 var child = thiz.__proto__.__child;
62 if (!child.__extended) {
63 var parent = thiz.__proto__.__parent;
64 child.__extended = parent.extend(child.name, child.prototype, true);
65 // This will deal with "i instanceof child"
66 child[Symbol.hasInstance] = function (instance) {
67 return instance instanceof this.__extended;
68 }
69 }
70 return child.__extended;
71 };
72
73 Parent.__activityExtend = function (parent, name, implementationObject) {
74 __log("__activityExtend called");
75 return parent.extend(name, implementationObject);
76 };
77
78 Parent.call = function (thiz) {
79 var Extended = extend(thiz);
80 thiz.__container__ = true;
81 if (arguments.length > 1) {
82 thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(arguments, 1))));
83 }
84 else {
85 thiz.__proto__ = new Extended()
86 }
87 return thiz.__proto__;
88 };
89
90 Parent.apply = function (thiz, args) {
91 var Extended = extend(thiz);
92 thiz.__container__ = true;
93 if (args && args.length > 0) {
94 thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args)));
95 }
96 else {
97 thiz.__proto__ = new Extended();
98 }
99 return thiz.__proto__;
100 };
101 __extends_ns(Child, Parent);
102 Child.__isPrototypeImplementationObject = true;
103 Child.__proto__ = Parent;
104 Child.prototype.__parent = Parent;
105 Child.prototype.__child = Child;
106 }
107

Calls 8

indexOfMethod · 0.80
extendMethod · 0.80
concatMethod · 0.80
__extends_tsFunction · 0.70
extendFunction · 0.70
__extends_nsFunction · 0.70
toStringMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected