-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from canjs/let-context-prototype
removing functions added by can-event-queue from LetContext.prototype
- Loading branch information
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var SimpleMap = require('can-simple-map'); | ||
|
||
// ### LetContext | ||
// Instances of this are used to create a `let` variable context. | ||
|
||
// Like Object.create, but only keeps Symbols and properties in `propertiesToKeep` | ||
function objectCreateWithSymbolsAndSpecificProperties(obj, propertiesToKeep) { | ||
var newObj = {}; | ||
|
||
// copy over all Symbols from obj | ||
if ("getOwnPropertySymbols" in Object) { | ||
Object.getOwnPropertySymbols(obj).forEach(function(key) { | ||
newObj[key] = obj[key]; | ||
}); | ||
} | ||
|
||
// copy over specific properties from obj (also fake Symbols properties for IE support); | ||
Object.getOwnPropertyNames(obj).forEach(function(key) { | ||
if (propertiesToKeep.indexOf(key) >= 0 || key.indexOf("@@symbol") === 0) { | ||
newObj[key] = obj[key]; | ||
} | ||
}); | ||
|
||
return Object.create(newObj); | ||
} | ||
|
||
var LetContext = SimpleMap.extend("LetContext", {}); | ||
LetContext.prototype = objectCreateWithSymbolsAndSpecificProperties(SimpleMap.prototype, [ | ||
// SimpleMap properties | ||
"setup", | ||
"attr", | ||
"serialize", | ||
"get", | ||
"set", | ||
"log", | ||
// required by SimpleMap properties | ||
"dispatch", | ||
// Construct properties (not added by can-event-queue) | ||
"constructorExtends", | ||
"newInstance", | ||
"_inherit", | ||
"_defineProperty", | ||
"_overwrite", | ||
"instance", | ||
"extend", | ||
"ReturnValue", | ||
"setup", | ||
"init" | ||
]); | ||
LetContext.prototype.constructor = LetContext; | ||
|
||
module.exports = LetContext; |
This file contains 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