Skip to content

Commit 6728f19

Browse files
author
smcq
committed
readme.
1 parent 02666aa commit 6728f19

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

readme.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#Prototypical Inheritance for Python
2+
3+
Implement javascript prototypal inheritance in python. This
4+
implementation will allow you to create new prototypes on the fly, or
5+
set prototypes for classes.
6+
7+
## Usage:
8+
9+
You can use it to make lightweight children from an existing object.
10+
11+
obj = Parent()
12+
obj_child = prototype(obj)
13+
14+
You can use it to make static prototypes for classes.
15+
16+
obj = Parent()
17+
18+
@prototype(obj)
19+
class Child(object):
20+
pass
21+
22+
obj2 = Child()
23+
24+
## Exlicit Generation
25+
26+
In some rare cases you must explicitly force a clone or a decorator to
27+
be created. If the object contains a `new` property you must
28+
explicitly call .new to force a clone to be made.
29+
30+
obj = Parent()
31+
obj.new = 1
32+
33+
obj_child = prototype(obj).new
34+
35+
36+
If the object contains a `__call__` property, you must explicitly
37+
create a decorator with the extend=True keyword argument.
38+
39+
obj = Parent()
40+
obj.__call__ = 1
41+
42+
@prototype(obj, extend=True)
43+
class Child(object):
44+
pass
45+
46+
##Nested Prototypes
47+
48+
Prototypes can extend prototypes as many levels as you want. One
49+
note, prototypes extending prototypes must use .new and extend=True.
50+
51+
obj = Parent()
52+
child = prototype(obj)
53+
grandchild = prototype(obj).new

0 commit comments

Comments
 (0)