Skip to content

Commit

Permalink
Use Object.create() and make manipulating F.prototype a fallback solu…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
evanvosberg committed Oct 27, 2016
1 parent 48b77cc commit 8edc21e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
* CryptoJS core components.
*/
var CryptoJS = CryptoJS || (function (Math, undefined) {
/*
* Local polyfil of Object.create
*/
var create = Object.create || (function () {
function F() {};

return function (obj) {
var subtype;

F.prototype = obj;

subtype = new F();

F.prototype = null;

return subtype;
};
}())

/**
* CryptoJS namespace.
*/
Expand All @@ -16,7 +35,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) {
* Base object for prototypal inheritance.
*/
var Base = C_lib.Base = (function () {
function F() {}


return {
/**
Expand All @@ -39,8 +58,7 @@ var CryptoJS = CryptoJS || (function (Math, undefined) {
*/
extend: function (overrides) {
// Spawn
F.prototype = this;
var subtype = new F();
var subtype = create(this);

// Augment
if (overrides) {
Expand Down

0 comments on commit 8edc21e

Please sign in to comment.