Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b59bbdd

Browse files
mixins, borrowing methods
1 parent f64c733 commit b59bbdd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎06-code-reuse.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,21 @@ function extend (parent, child) {
163163
* shallow copy just copies references of arrays and object
164164
* children can modify parent properties :(
165165
* deep copy is when array elements and object properties are copied as well
166+
167+
## mixins
168+
169+
* just deep copy all properties from multiple objects and mix in to a new Object
170+
* not like mixins in other languages, here: no link to parent
171+
172+
## borrowing methods
173+
174+
* sometimes you want to use one or two methods of an existing Objects
175+
* you don't want a parent-child relationship with that Object
176+
* can be done with ```call``` and ```apply```
177+
* pass in your object to bind ```this``` to within the function
178+
179+
```js
180+
notMyObject.doStuff.call(myObject, param1, param2);
181+
//or
182+
notMyObject.doStuff.apply(myObject, [param1, param2]);
183+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /