Comparing version 2.2.0 to 2.2.1
{ | ||
"name" : "es5class", | ||
"main" : "index.js", | ||
"version" : "2.2.0", | ||
"version" : "2.2.1", | ||
"homepage" : "https://github.com/pocesar/ES5-Class", | ||
@@ -6,0 +6,0 @@ "authors" : [ |
@@ -0,1 +1,6 @@ | ||
## 2.2.1 | ||
* Changes to documentation, mostly `README.md` | ||
* Fixed bug that makes `$implement` apply descriptors correctly | ||
* Performance tweaks | ||
## 2.2.0 | ||
@@ -2,0 +7,0 @@ * Add `$wrap` method, makes any function or object an ES5Class |
/* ============================================================ | ||
* bootstrap-dropdown.js v2.3.1 | ||
* http://twitter.github.com/bootstrap/javascript.html#dropdowns | ||
* bootstrap-dropdown.js v2.3.2 | ||
* http://getbootstrap.com/2.3.2/javascript.html#dropdowns | ||
* ============================================================ | ||
* Copyright 2012 Twitter, Inc. | ||
* Copyright 2013 Twitter, Inc. | ||
* | ||
@@ -55,2 +55,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
if (!isActive) { | ||
if ('ontouchstart' in document.documentElement) { | ||
// if mobile we we use a backdrop because click events don't delegate | ||
$('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus) | ||
} | ||
$parent.toggleClass('open') | ||
@@ -108,2 +112,3 @@ } | ||
function clearMenus() { | ||
$('.dropdown-backdrop').remove() | ||
$(toggle).each(function () { | ||
@@ -163,3 +168,2 @@ getParent($(this)).removeClass('open') | ||
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) | ||
.on('click.dropdown-menu', function (e) { e.stopPropagation() }) | ||
.on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle) | ||
@@ -166,0 +170,0 @@ .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) |
@@ -49,67 +49,5 @@ (function($) { | ||
//Perform search and hide unmatched elements | ||
var tocList; | ||
var treeObject = {}; | ||
//Create the tree | ||
var createTree = function(ul) { | ||
var prevLevel = {level: -1, index: -1, parent: -1, val: ''}; | ||
var levelParent = {0: -1}; | ||
tocList = ul.children("li"); | ||
tocList.each(function(i) { | ||
var me = $(this).removeClass("toc-active"); | ||
var currentLevel = parseInt(me.attr('class').trim().slice(-1)); | ||
if (currentLevel > prevLevel.level) { | ||
currentParent = prevLevel.index; | ||
} else if (currentLevel == prevLevel.level) { | ||
currentParent = prevLevel.parent; | ||
} else if (currentLevel < prevLevel.level) { | ||
currentParent = levelParent[currentLevel] || prevLevel.parent; | ||
} | ||
levelParent[currentLevel] = currentParent; | ||
var currentVal = $('a', this).text().trim().toLowerCase(); | ||
treeObject[i] = { | ||
val: currentVal, | ||
level: currentLevel, | ||
parent: currentParent | ||
} | ||
prevLevel = {index: i, val: currentVal, level: currentLevel, parent: currentParent}; | ||
}); | ||
} | ||
//Show the parents recursively | ||
var showParents = function(key) { | ||
var me = treeObject[key]; | ||
if (me.parent > -1) { | ||
$(tocList[me.parent]).show(); | ||
showParents(me.parent); | ||
} | ||
}; | ||
//Perform the search | ||
var search = function(searchVal) { | ||
searchVal = searchVal.trim().toLowerCase(); | ||
for (var key in treeObject) { | ||
var me = treeObject[key]; | ||
if (me.val.indexOf(searchVal) !== -1 || searchVal.length == 0) { | ||
$(tocList[key]).show(); | ||
if ($(tocList[me.parent]).is(":hidden")) { | ||
showParents(key); | ||
} | ||
} else { | ||
$(tocList[key]).hide(); | ||
} | ||
} | ||
} | ||
return this.each(function() { | ||
//build TOC | ||
var el = $(this); | ||
var searchVal = ''; | ||
var searchForm = $("<form/>", {class: "form-search quick-search"}) | ||
.append($("<input/>", {type: "text", class: "input-medium search-query", placeholder: "Quick Search"})) | ||
.append($("<i/>", {class: "icon icon-search search-icon"})); | ||
searchForm.css({'position': 'fixed', 'top': '45px', 'padding-right': '20px'}); | ||
$(".search-icon", searchForm).css({'marginLeft': '-20px', 'marginTop': '3px'}); | ||
var ul = $('<ul/>'); | ||
@@ -139,49 +77,2 @@ headings.each(function(i, heading) { | ||
el.html(ul); | ||
el.parent().prepend(searchForm); | ||
el.css({'top': '80px'}); | ||
//create the tree | ||
createTree(ul) | ||
//set intent timer | ||
var intentTimer; | ||
var accumulatedTime = 0; | ||
//bind quick search | ||
el.siblings('.quick-search').children('.search-query').bind('keyup', function(e) { | ||
if (accumulatedTime < 1000) { | ||
window.clearTimeout(intentTimer); | ||
} | ||
var me = $(this); | ||
if (me.val().length > 0) { | ||
$(".search-icon").removeClass("icon-search").addClass("icon-remove-circle").css('cursor', 'pointer'); | ||
} else { | ||
$(".search-icon").removeClass("icon-remove-circle").addClass("icon-search").css('cursor', 'auto'); | ||
} | ||
var intentTime = 500 - (me.val().length * 10); | ||
accumulatedTime += intentTime; | ||
intentTimer = window.setTimeout(function() { | ||
if (searchVal == me.val()) { | ||
return false; | ||
} | ||
searchVal = me.val(); | ||
search(me.val()); | ||
accumulatedTime = 0; | ||
}, intentTime); | ||
}); | ||
// Make text clear icon work | ||
$(".search-icon").click(function(e) { | ||
if($(this).hasClass('icon-remove-circle')) { | ||
$('.search-query').val('').trigger('keyup'); | ||
} else { | ||
$('.search-query').focus(); | ||
} | ||
}); | ||
//set positions of search box and TOC | ||
var navHeight = $(".navbar").height(); | ||
var searchHeight = $(".quick-search").height(); | ||
$(".quick-search").css({'top': navHeight + 10 + 'px', 'position': 'fixed'}); | ||
el.css('top', navHeight + searchHeight + 15 + 'px'); | ||
}); | ||
@@ -188,0 +79,0 @@ }; |
18
index.js
@@ -34,3 +34,5 @@ (function (root, factory){ | ||
'prototype': true, | ||
'$original': true | ||
'$original': true, | ||
'__length': true, | ||
'$currentContext': true | ||
}, | ||
@@ -581,3 +583,9 @@ hasSuperRegex = /\([^\$]*\$super[^\)]*\)(?=\s*\{)/m; | ||
descriptor = gpd(obj, key); | ||
if (descriptor !== undefined && (descriptor.set || descriptor.get)) { | ||
if (descriptor !== undefined && ( | ||
descriptor.set || | ||
descriptor.get || | ||
descriptor.writable === false || | ||
descriptor.configurable === false || | ||
descriptor.enumerable === false) | ||
) { | ||
Object.defineProperty(self, key, descriptor); | ||
@@ -734,3 +742,3 @@ } else { | ||
Object.defineProperty(ES5Class, '$version', { | ||
value: '2.2.0' | ||
value: '2.2.1' | ||
}); | ||
@@ -952,7 +960,3 @@ | ||
configurables = { | ||
'$destroy': true | ||
}; | ||
return ES5Class; | ||
})); |
@@ -21,3 +21,3 @@ { | ||
"outputSourcePath" : false, | ||
"systemName" : "ES5Class", | ||
"systemName" : "Prototypal class inheritance for Node.js and the browser", | ||
"footer" : "", | ||
@@ -24,0 +24,0 @@ "copyright" : "", |
{ | ||
"name": "es5class", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Prototypal inheritance based on ES5 Object.create and Object.defineProperty for node.js and modern browsers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
211
README.md
@@ -5,2 +5,3 @@ [](https://travis-ci.org/pocesar/ES5-Class) | ||
[](https://github.com/pocesar/ES5-Class) | ||
 | ||
@@ -13,2 +14,4 @@ <!-- [](https://ci.testling.com/pocesar/ES5-Class) --> | ||
## Highlights | ||
A Class object that enables native prototypal inheritance for Node and modern browsers. | ||
@@ -25,3 +28,3 @@ | ||
* Uses `Object.setPrototypeOf` (when available, using `__proto__` when isn't), `Object.create` and `Object.defineProperty` ES5/ES6 methods to enable native prototypal inheritance with proper settings (enumerable, configurable, writable) | ||
* Works with Node.js 0.8.x and up, and modern browsers (IE11, Firefox, Chrome, Safari). | ||
* Works with Node.js 0.8.x and up (including node-webkit), and really modern browsers (IE11, Firefox, Chrome, Safari). | ||
* Functions to implement other class methods and include other instance/prototype methods | ||
@@ -31,3 +34,3 @@ * The `$implement` method imports both prototype and class methods | ||
* Takes advantage of ES5 non-writable properties to disable the possibility of messing up the classes | ||
* Ability to inherit from multiple classes using arrays using `Class.$define('YourClass', [Class1, Class2, Class3])` without setting the `$parent` class, working like mixins/traits | ||
* Ability to inherit from multiple classes using arrays using `ES5Class.$define('YourClass', [Class1, Class2, Class3])` without setting the `$parent` class, working like mixins/traits | ||
* Inject and call `$super` to reach the parent instance class functions or extended class method | ||
@@ -40,2 +43,6 @@ * Call `this.$parent` to reach the parent class definition inside your methods | ||
## Documentation | ||
See docs in [ES5Class Documentation](http://pocesar.github.io/ES5-Class) | ||
## Breaking changes | ||
@@ -59,4 +66,4 @@ | ||
var Sub = Base.$define('Sub', { | ||
construct: function(){ | ||
this.$super('that','those'); | ||
construct: function(those){ | ||
this.$super('that', those); | ||
} | ||
@@ -87,11 +94,6 @@ }); | ||
`$super` is _merely_ a shortcut for `this.$parent.prototype.fn.apply(this, arguments);` (actually a bit fancier than that). | ||
Nothing stops you from doing that by yourself (if you don't fancy the `$super` argument) | ||
Nothing stops you from doing that by yourself (if you don't fancy the `$super` argument injection) | ||
In version 2.x you'll also need [better-curry](https://github.com/pocesar/js-bettercurry) as a dependency. | ||
##### Contributors | ||
* [bfil](https://github.com/bfil) | ||
* [pocesar](https://github.com/pocesar) | ||
## Install | ||
@@ -115,3 +117,3 @@ | ||
// or with RequireJS | ||
define(['ES5Class'], function(ES5Class){ | ||
require(['ES5Class'], function(ES5Class){ | ||
@@ -121,6 +123,2 @@ }); | ||
## Documentation | ||
See docs in [ES5Class Documentation](http://pocesar.github.io/ES5-Class) | ||
## Example usage | ||
@@ -131,3 +129,3 @@ | ||
```javascript | ||
var Animal = Class.$define( | ||
var Animal = ES5Class.$define( | ||
// Class Name | ||
@@ -159,15 +157,21 @@ 'Animal', | ||
construct: function ($super, name, canFly){ | ||
// calls parent class constructor, calls Animal.prototype.construct | ||
// and set this.name | ||
if (canFly) { | ||
this.canFly = canFly; | ||
} | ||
$super(name + ' Bird'); // calls parent class constructor, calls Animal.prototype.construct and set this.name = 'Yellow ' + name | ||
$super(name + ' Bird'); | ||
}, | ||
canFly : false | ||
// Bird.prototype.canFly | ||
canFly : false | ||
}); | ||
``` | ||
#### Extending a prototype | ||
#### Extending the prototype | ||
```javascript | ||
Bird.$include({ // include is like doing _.extend(Bird.prototype, {}) but with proper wrapping the methods for $super access | ||
// append functions to the prototype. existing functions in the prototype are | ||
// wrapped for $super access | ||
Bird.$include({ | ||
// Bird.prototype.fly | ||
fly: function (){ | ||
@@ -183,8 +187,9 @@ if (this.canFly) { | ||
#### Implement | ||
#### Add static and prototype members to the class | ||
```javascript | ||
// "Implement" import prototype (if any) and class methods from the given object, to the class declaration and the prototype | ||
// "Implement" import the prototype (if it has a prototype) and class methods from the | ||
// given object, to the class declaration | ||
var | ||
Class1 = Class.$define('Class1'), | ||
Class1 = ES5Class.$define('Class1'), | ||
obj = {yup: true}, | ||
@@ -201,3 +206,4 @@ h = function(){}; | ||
You can all the inheriting class construct by passing the second parameter, for example: | ||
You can call the inheriting class `$super` construct by passing true to the second parameter, | ||
for example: | ||
@@ -208,3 +214,3 @@ ```javascript | ||
// this code is the same as | ||
Class.$define('MyEventEmitter', function(){ | ||
ES5Class.$define('MyEventEmitter', function(){ | ||
this.$implement(EventEmitter); | ||
@@ -220,17 +226,19 @@ | ||
// this one (much cleaner) | ||
Class.$define('MyEventEmitter').$implement(EventEmitter, true); | ||
ES5Class.$define('MyEventEmitter').$implement(EventEmitter, true); | ||
// There's no need for the construct + implement if you are just creating an inheritance from another Node.js class | ||
// So it's easier to set the second parameter of implement to true, it will call the parent class constructor | ||
// automatically | ||
// There's no need for the construct + implement if you are just creating | ||
// an inheritance from another Node.js class | ||
// So it's easier to set the second parameter of implement to true, it | ||
// will call the parent class constructor automatically | ||
``` | ||
Because it's really easy to forget to initialize the inheriting class | ||
Because it's really easy to forget to initialize the super constructor of the inheriting class | ||
#### Include | ||
#### Include (mixin) to the current prototype | ||
```javascript | ||
// "Implement" import class methods *ONLY* from the given object, to the class declaration prototype *ONLY* | ||
// "Implement" import class methods *ONLY* from the given object, | ||
// to the class declaration prototype *ONLY* | ||
var | ||
Class1 = Class.$define('Class1'), | ||
Class1 = ES5Class.$define('Class1'), | ||
obj = {yup: true}, | ||
@@ -244,12 +252,16 @@ h = function(){}; | ||
console.log(Class1.$create().yup); // true (imported to the prototype) | ||
console.log(Class1.nope); // undefined (not imported since it's in the prototype of the "h" object) | ||
console.log(Class1.$create().nope); // undefined (not imported since it's in the prototype of the "h" object) | ||
console.log(Class1.$create().yep); // false (imported to the prototype since it's in the declaration of the "h" object) | ||
// true (imported to the prototype) | ||
console.log(Class1.$create().yup); | ||
// undefined (not imported since it's in the prototype of the "h" object) | ||
console.log(Class1.nope); | ||
// undefined (not imported since it's in the prototype of the "h" object) | ||
console.log(Class1.$create().nope); | ||
// false (imported to the prototype since it's in the declaration of the "h" object) | ||
console.log(Class1.$create().yep); | ||
``` | ||
#### Inherit from any existing Node.js class | ||
#### Inherit from any existing (Node.js) class | ||
```javascript | ||
var MyEventClass = Class.$define('MyEventEmitter', function(){ | ||
var MyEventClass = ES5Class.$define('MyEventEmitter', function(){ | ||
var base = this; | ||
@@ -272,8 +284,27 @@ base.$implement(require('events').EventEmitter); // inherit from EventEmitter | ||
}); | ||
// or | ||
MyEventClass.$inherit(require('events').EventEmitter, []); | ||
``` | ||
#### Constants | ||
```javascript | ||
var | ||
MyClass = ES5Class.$define('MyClass').$const({ | ||
cant: 'touch this' | ||
}); | ||
MyClass.cant = false; | ||
// still 'touch this' | ||
// throws exception on strict mode | ||
``` | ||
#### Encapsulate logic by passing a closure | ||
```javascript | ||
Bird.$include(function (_super){ // _super is the Animal prototype (the parent), it contains only "construct" and "getName" per definitions above | ||
Bird.$include(function (_super){ | ||
// _super is the Animal prototype (the parent), it contains only | ||
// "construct" and "getName" per definitions above | ||
// "super" is a javascript reserved word, that's why it's being called _super here | ||
@@ -295,3 +326,5 @@ var timesBeaked = 0; | ||
Bird.$implement(function (_super){ // _super is the Animal class itself (the parent) | ||
Bird.$implement(function (_super){ | ||
// _super is the Animal class itself (the parent) | ||
// "this" refers to the current Class definition, the same way it happens | ||
@@ -301,2 +334,3 @@ // when extending the prototype (using $include), you may access this.prototype in | ||
var catalog = {}; | ||
return { | ||
@@ -315,5 +349,42 @@ catalog: function (bird){ // Bird.catalog() is now available | ||
#### Extending a class | ||
#### Exchange the instance prototype chain | ||
```javascript | ||
var MyEmptyClass = ESClass.$define('MyEmptyClass'); | ||
MyEmptyClass.$create().$exchange(Error); // MyEmptyClass instance now 'looks like' an Error instance | ||
``` | ||
#### Import an object to the current instance | ||
```javascript | ||
var MyEmptyClass = ESClass.$define('MyEmptyClass'); | ||
var instance = MyEmptyClass.$create().$import({ | ||
somenew: function(){ | ||
} | ||
}); | ||
instance.somenew(); | ||
``` | ||
#### Enumerate members | ||
```javascript | ||
ES5Class.$define('MyClass',{ | ||
some:'member', | ||
somefn:function(){} | ||
}).$create().$names; | ||
// ['some','somefn'] | ||
``` | ||
#### Wrap an existing object or function as an ES5Class | ||
```javascript | ||
var someRandomObject = {}; | ||
var MyClass = ES5Class.$wrap(someRandomObject, 'MyClass'); // creates a new class | ||
ES5Class.$wrap(MyClass); // returns itself | ||
``` | ||
#### Prototypal inheritance from another class | ||
```javascript | ||
// These functions and values persist between class creation, serve as static methods | ||
@@ -350,2 +421,5 @@ Animal.$implement({ | ||
Dog.run(); // Dog.ran is now 40, Animal.ran and Cat.ran are now 20 | ||
// primitives are copied over to new classes (in this case, Cat and Dog) | ||
// objects retain their reference between all classes | ||
``` | ||
@@ -385,11 +459,11 @@ | ||
#### Mixin from other classes | ||
#### Mixin from other classes (Object composition) | ||
```javascript | ||
var Class1 = Class.$define('Class1', {}, {done: true}), | ||
Class2 = Class.$define('Class2', {func: function(){ return true; }}), | ||
Class3 = Class.$define('Class3', {}, {yet: true}); | ||
var Class1 = ES5Class.$define('Class1', {}, {done: true}), | ||
Class2 = ES5Class.$define('Class2', {func: function(){ return true; }}), | ||
Class3 = ES5Class.$define('Class3', {}, {yet: true}); | ||
// This mix in the whole class (prototype and class methods) | ||
var NewClass = Class.$define('NewClass', {}, [Class1, Class2, Class3]); | ||
var NewClass = ES5Class.$define('NewClass', {}, [Class1, Class2, Class3]); | ||
@@ -411,3 +485,3 @@ // Pay attention that it needs to go in the second parameter if you want | ||
// This mix in class methods as prototypes | ||
NewClass = Class.$define('NewClass', [Class1, Class2, Class3]); | ||
NewClass = ES5Class.$define('NewClass', [Class1, Class2, Class3]); | ||
@@ -422,3 +496,3 @@ console.log(NewClass.$create().yet); // true | ||
```javascript | ||
var Singleton = Class.$define('Singleton', {}, { | ||
var Singleton = ES5Class.$define('Singleton', {}, { | ||
staticHelper: function(){ | ||
@@ -430,6 +504,9 @@ return 'helper'; | ||
var ExtraSingleton = Class.$define('Extra'); | ||
var ExtraSingleton = ES5Class.$define('Extra'); | ||
ExtraSingleton.$implement(Singleton); | ||
ExtraSingleton.$implement({ | ||
extra: true | ||
extra: true, | ||
staticHelper: function($super){ | ||
return 'Extra' + $super(); | ||
} | ||
}); | ||
@@ -441,2 +518,3 @@ | ||
ExtraSingleton.staticVariable // 1 | ||
ExtraSingleton.staticHelper(); // 'Extrahelper' | ||
``` | ||
@@ -447,3 +525,3 @@ | ||
```javascript | ||
var Share = Class.$define('Share', function(){ | ||
var Share = ES5Class.$define('Share', function(){ | ||
var _data = {}; //all private data, that is shared between each Share.$create() | ||
@@ -471,3 +549,3 @@ | ||
```javascript | ||
var Op = Class.$define('Op', { | ||
var Op = ES5Class.$define('Op', { | ||
construct: function (number){ | ||
@@ -499,3 +577,3 @@ this.number = number; | ||
var Operation = Class.$define('Operation', {}, function (){ | ||
var Operation = ES5Class.$define('Operation', {}, function (){ | ||
var | ||
@@ -573,12 +651,12 @@ classes = [], | ||
``` | ||
class instance function call x 114,056,673 ops/sec ±6.33% (33 runs sampled) | ||
class method function call x 114,195,944 ops/sec ±3.86% (70 runs sampled) | ||
class instance included function call x 105,647,876 ops/sec ±4.55% (43 runs sampled) | ||
$super instance function calls x 14,142,842 ops/sec ±0.40% (98 runs sampled) | ||
$super class function calls x 13,981,525 ops/sec ±0.27% (99 runs sampled) | ||
$super inherited two levels deep function calls x 6,966,387 ops/sec ±0.42% (97 runs sampled) | ||
class.$create instantiation x 1,901,561 ops/sec ±1.51% (90 runs sampled) | ||
new operator x 4,526,628 ops/sec ±0.70% (97 runs sampled) | ||
obj() instance x 1,246,228 ops/sec ±2.01% (89 runs sampled) | ||
ES5Class.$define x 12,414 ops/sec ±2.40% (86 runs sampled) | ||
class instance function call x 125,269,746 ops/sec ±10.00% (34 runs sampled) | ||
class method function call x 123,280,719 ops/sec ±4.17% (40 runs sampled) | ||
class instance included function call x 103,738,852 ops/sec ±3.78% (42 runs sampled) | ||
$super instance function calls x 14,187,910 ops/sec ±0.44% (96 runs sampled) | ||
$super class function calls x 13,874,190 ops/sec ±0.73% (96 runs sampled) | ||
$super inherited two levels deep function calls x 6,910,075 ops/sec ±0.40% (100 runs sampled) | ||
class.$create instantiation x 1,832,552 ops/sec ±1.69% (91 runs sampled) | ||
new operator x 4,544,620 ops/sec ±0.37% (98 runs sampled) | ||
obj() instance x 1,225,367 ops/sec ±2.45% (96 runs sampled) | ||
ES5Class.$define x 12,106 ops/sec ±2.73% (85 runs sampled) | ||
``` | ||
@@ -604,2 +682,7 @@ | ||
##### Contributors | ||
* [bfil](https://github.com/bfil) | ||
* [pocesar](https://github.com/pocesar) | ||
## License | ||
@@ -606,0 +689,0 @@ |
@@ -498,2 +498,22 @@ describe('ES5Class', function (){ | ||
describe('$implement', function(){ | ||
it('ES5Class', function(){ | ||
var Base = ES5Class.$define('Base', { | ||
proto: 1 | ||
}, { | ||
static: 1 | ||
}), Sub = ES5Class.$define('Sub'); | ||
Sub.$implement(Base); | ||
expect(Sub.static).to.be(Base.static); | ||
Base.proto = 2; | ||
expect(Sub.static).to.be(1); | ||
Base.prototype.proto = 2; | ||
expect(Sub.$create().proto).to.be(1); | ||
}); | ||
}); | ||
it('old school new operator', function (done){ | ||
@@ -763,2 +783,28 @@ var NewCls, Cls = ES5Class.$define('Cls', { | ||
}); | ||
it('inherits const from base class', function(){ | ||
var | ||
Base = ES5Class.$define('Base') | ||
.$const({myConst: 1}) | ||
.$const({myProtoConst: 1}, true), | ||
Sub = Base.$define('Sub'); | ||
expect(Sub.myConst).to.be(Base.myConst); | ||
expect(Sub.$create().myProtoConst).to.be(Base.prototype.myProtoConst); | ||
}); | ||
it('applies writable false when mixin', function(){ | ||
var | ||
Base = ES5Class.$define('Base') | ||
.$const({myConst: 1}) | ||
.$const({myProtoConst: 1}, true), | ||
Sub = ES5Class.$define('Sub'); | ||
Sub.$implement(Base); | ||
expect(Sub.myConst).to.be(Base.myConst); | ||
expect(Sub.$create().myProtoConst).to.be(Base.prototype.myProtoConst); | ||
Sub.myConst = 2; | ||
expect(Sub.myConst).to.be(1); | ||
}); | ||
}); | ||
@@ -1583,2 +1629,29 @@ | ||
it('toString and valueOf', function(){ | ||
var Cls = ES5Class.$define('Cls', { | ||
toString: function(){ | ||
return 'prototype'; | ||
} | ||
}, { | ||
toString: function(){ | ||
return 'static'; | ||
} | ||
}); | ||
expect('' + Cls()).to.be('prototype'); | ||
expect('' + Cls).to.be('static'); | ||
Cls.$implement({ | ||
valueOf: function(){ | ||
return 'static valueOf'; | ||
} | ||
}); | ||
Cls.$include({ | ||
valueOf: function(){ | ||
return 'prototype valueOf'; | ||
} | ||
}); | ||
expect('' + Cls()).to.be('prototype valueOf'); | ||
expect('' + Cls).to.be('static valueOf'); | ||
}); | ||
it('constructor', function (){ | ||
@@ -1585,0 +1658,0 @@ expect(typeof Bird).to.be('function'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3066059
60
100330
680