Giter VIP home page Giter VIP logo

Comments (10)

kriskowal avatar kriskowal commented on May 20, 2024

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.

Raynos avatar Raynos commented on May 20, 2024

I'll put it on the TODO list and see if I get there.

from es5-shim.

domenic avatar domenic commented on May 20, 2024

Holy crap, nice find.

from es5-shim.

Raynos avatar Raynos commented on May 20, 2024

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.

WebReflection avatar WebReflection commented on May 20, 2024

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.

Raynos avatar Raynos commented on May 20, 2024

@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.

WebReflection avatar WebReflection commented on May 20, 2024

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 simply function (object, property, definition) {object[property] = definition; return object} while for others will be Object.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.

Raynos avatar Raynos commented on May 20, 2024

Can JS objects inherit from VB objects created from new VBClass(...)

from es5-shim.

WebReflection avatar WebReflection commented on May 20, 2024

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.

kriskowal avatar kriskowal commented on May 20, 2024

I am closing this. Doesn’t seem that we can cheat.

from es5-shim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.