JS Prototype methods for entity instances RRS feed

  • Question

  • Hi all,

    With regard to JS prototype  (example below extracted from this article) :

    myapp.Order.created = function (entity) {
        // Set Default Date
        entity.OrderDate = new Date();

    // Calculated field to count Available OrderDetail
    myapp.Order.prototype.getAvailable = function () {
        return this.OrderDetails.sum(function (item) {
            return item.ItemAvailable == true;

    I can get anthing from 'this' (related collections etc), but what I CAN'T get hold of is the 'details' instance of 'this'(Order).

    I'm wanting to attach a method (or possibly a property) on all Order instances so that I can return or inspect the 'EntityState' value thus;

    return this.details.EntityState

    however 'details' is unavailable in intellisense within these prototype methods declared outside of myapp.Order.created. It IS available in myapp.Order.created but only as 'entity.details'

    Any ideas why 'this' in these circumstances allows me to select from any entity property/collection except for 'details'?



    Ian Mac

    Tuesday, July 1, 2014 1:28 PM


  • Placing a break point inside either getAvailable or getUnavailable shows that both

    • this.details.EntityState
    • this.details.hasEdits

    are both validly defined properties.

    Don't necessarily rely on VS IDE IntelliSense as it is frequently, well, crap when it comes to JavaScript.  It's more reliable to look for these properties using the IntelliSense in the JavaScript console while the app is running, or in FireFox's Firebug extension, which is excellent for this purpose.  ReSharper was able to correctly find these properties as well.

    • Edited by LittleBobbyTables Friday, July 4, 2014 4:13 AM
    • Proposed as answer by Xpert360 Friday, July 4, 2014 7:56 AM
    • Marked as answer by Angie Xu Friday, July 11, 2014 6:36 AM
    Friday, July 4, 2014 4:12 AM