Comments (10)
Cute. Depending on how heavy this turns out to be, I would consider either incorporating such a fix, or providing an extra script that folks can use if they’re extra-desperate to get shims working in IE. Unfortunately, I’m not set up to take this project on myself.
from es5-shim.
I'll put it on the TODO list and see if I get there.
from es5-shim.
Holy crap, nice find.
from es5-shim.
Andreas claims in the comments that turning this into a shim is not possible.
I wil still leave this open and do my own research, but it's likely this is a lie.
from es5-shim.
you cannot add runtime VB Classes instances properties or methods ... VB Classes are static so all you may create is a sort of Object.createFrozen(descriptor); which is nowhere in ES5 specs.
I use VBClass on daily basis and it scales quite well (even in IE7 mobile for old WP) but if you define runtime thousands of classes then it's problematic ... VBClass is good for static classes, JS developers may not like them due "unknown" typeof, inability to extends other classes through prototype, and impossible to borrow methods or attach property runtime.
http://webreflection.blogspot.com/2011/03/rewind-getters-setters-for-all-ie-with.html
from es5-shim.
@WebReflection I was thinking it may be possible to implement a
var vbObject = Object.createNonExtensible(proto, descriptor)
And then use Object.create(vbObject, moredescriptors)
. If those are possible then getter/setters in oldIE at least have some use even though the actual vbObject
cannot be extended.
Alternatively would it be possible for var b = Object.defineProperties(a, descriptors)
to return a b that has all the properties of a copied over and the descriptors applied to itself? that way we can add a massive disclaimer that a
is not extended but b
has getter/setters on it for oldIE.
from es5-shim.
Object.createNonExtendible(proto, descriptor
) is still not good enough 'cause in IE you cannot inherit from JS objects in VB so the proto should go and we need to mixin descriptors.
Object.defineProperties()
is not possible because it will need to create a new class per each call and a
won't be extended at all so ... as shim, is too broken.
The way I use VBClass is OK as it is for me but here a sort of workflow I am following for dynamic use cases
- prepare a generic empty object
var obj = {};
- define the needed
definePorperty
, for IE < 9 this will be simplyfunction (object, property, definition) {object[property] = definition; return object}
while for others will beObject.defineProperty
or a simple shim based on__defineG/Setter__
- use
defineProperty(obj, "key", descriptor)
; per each property I want in that object - at the end of the function ...
if (IE < 9) { obj = VBClass("__vb__" + counter++); return new obj; } return obj;
The counter
property is private and incremented per each instance I need to define runtime with getters and setters for IE < 9 too ... this is a lot of overhead for IE if we need to define runtime thousands of dynamic objects ( thousands of VBClass ) but this is not my case ... actually I create few instances of these objects so I don't mind and I would define classes statically if objects needs to be many.
For latter case, if necessary, all we need to do is to add a data
property as null in the class definition so that each object can use this property as trash bin and reuse it inside methods
var MyClass = VBClass("MyClass", { data: {value: null}, name: { get: function () { return this.data.name; }, set: function (name) { this.data.name = name; } } });
Bear in mind also properties defined with an underscore, to emulate protected properties, will fail in VB world
_notOK
while isOK_
is fine.
Last, but not least, these objects are aliens for normal JS devs so use VBClass carefully ;-)
from es5-shim.
Can JS objects inherit from VB objects created from new VBClass(...)
from es5-shim.
as far as I remember no ... but you see there are too many "gotchas" able to make the shim highly improbable :-/
Drop IE < 9 ... easy :D
from es5-shim.
I am closing this. Doesn’t seem that we can cheat.
from es5-shim.
Related Issues (20)
- All V8 versions have the Date shim loaded. HOT 1
- Rounding errors with toExponential in Edge 15/16 HOT 4
- IE9 error: Redeclaration of const property HOT 5
- Something in the shim causes Chrome to throw a warning HOT 3
- 4.5.11 got a tag, but not a full release HOT 2
- `hasAutomationEqualityBug` triggers deprecation warnings in Firefox
- Cannot convert undefined or null to object PropTypes.shape() HOT 9
- Question: Why concatenate Symbols with a string without assigning it to a variable? HOT 6
- Why not set bound.prototype = target.prototype directly? HOT 3
- in ie8 Object.keys failed this conversion HOT 3
- Action required: Greenkeeper could not be activated 🚨
- String#lastIndexOf has a shallow-wrapper shim that does nothing and always gets applied HOT 1
- Dependency Dashboard
- Conflict ES5-shim(sham) 4.5.15 and ES6-shim(sham) 0.35.x HOT 19
- Please change the name of the default branch HOT 1
- External URL linking to spam websites HOT 2
- errors with Object.defineProperty under ie8 since 4.6.3 HOT 6
- Incompatibility with awilix HOT 17
- Invalid Date on Safari HOT 2
- ⚠️ `webkitStorageInfo` is going away HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es5-shim.