Welcome To Snipplr


Everyone's Recent JavaScript Snippets Tagged object



« Prev 1 2 3
  1. FAV

    Remove an item from array using UnderscoreJS

    Using underscore.js, you could combine .findWhere with .without Although, since you are creating a new array in this case anyway, you could simply use _.filter or the native Array.prototype.filter function (just like shown in the other question)....
    JavaScript 19 views posted 4 years ago by Balamir
  2. FAV

    Copy object by value instead of by reference

    To do this for any object in JavaScript will not be simple or straightforward. You will run into the problem of erroneously picking up attributes from the object's prototype that should be left in the prototype and not copied to the new instance. If,...
    JavaScript 8 views posted 4 years ago by BrentS
  3. FAV

    Javascript object template

    A template for a javascript object with a object.create shiv to condense into object prototypes
    JavaScript 12 views posted 5 years ago by rickygri
  4. FAV

    Create new Object From Variable in JavaScript

    This example of code allows you to create a new object in javascript (using simple inheritance) such that the class of the object is defined from a variable. After creating the object you may use it for your purposes.
    JavaScript 7 views posted 5 years ago by apphp-snippets
  5. FAV

    OOP Javascript Template with constructor and inheritance

    From @blixt http://stackoverflow.com/users/119081/blixt As you can see, the classes correctly interact with each other (they share the static id from MyClass, the announce method uses the correct get_name method, etc.) One thing to note is the...
    JavaScript saved by 2 people 11 views posted 5 years ago by rickygri
  6. FAV

    Template for a Javascript function with optional and mandatory arguments passed as an object collection

    A simple template for a JavaScript function which allows for an arbitrary number of named arguments to be passed in. This is achieved by passing a single object as an argument with each of the 'real' arguments being a key/value pair. In this way argu...
    JavaScript 16 views posted 7 years ago by davidwaterston
  7. FAV

    JSON Tree(1 function 15 lines)Nested Ul from single or multidimensional json object

    Any valid json object will be recursively traversed building a nested unordered list of its properties and their values. This example parses the json entered in the text area into an object that is passed to the json_tree() function. I use the twit...
    JavaScript 19 views posted 7 years ago by halk
  8. FAV

    Make an empty object in JavaScript

    `Object.create(null)` is a more memory-efficient way to make objects, but it's not supported in all versions of JavaScript, so you can do the "old-fashioned" `{}` if that function isn't available.
    JavaScript 2 views posted 7 years ago by EvanHahn
  9. FAV

    Get Object Size in JS

    Function to validate the existence of each key in the object to get the number of valid key/value pairs.
    JavaScript 7 views posted 7 years ago by reverend
  10. FAV

    Optional function arguments/parameters by using associative array

    By not being limited to provide certain arguments/parameters in right order when calling a function, makes the function more versatile and easier to extend without breaking old code (e.g. calls to the function). One solution is to pass an associati...
    JavaScript 11 views posted 8 years ago by coprolit
  11. FAV

    JavaScript Object Prototypal inheritance

    an operator that implements true prototypal Object inheritance in JavaScript
    JavaScript 4 views posted 8 years ago by luizlopes
  12. FAV

    get RGBA values as an object

    this function gets a parameter like an hex color (es: "#ffffff"), an abbreviated hex color (es: "#fff"), an rgb color (es: "rgb(255,255,255)") or an rgba color (es: "rgba(255,255,255,1)"), and returns an object containing the rgba values, like { red:...
    JavaScript 7 views posted 8 years ago by claudiowebdesign
  13. FAV

    Classes objects prototype and static

    JavaScript 3 views posted 8 years ago by devnull69
  14. FAV

    Iterate through keys in an object literal and return the key name.

    Returns the key name in mainObject if it's a key, and hasOwnProperty of key (to rule out the prototype object. Then it also checks if the key is listed in an array using a jquery function and also tests if it's null.
    JavaScript 9 views posted 8 years ago by supermauerbros
  15. FAV

    Switch using an Object

    Using an object as a simple switch.
    JavaScript 2 views posted 8 years ago by 1man
  16. FAV

    Cross-browser javascript event capture

    JavaScript 4 views posted 8 years ago by onblur
  17. FAV

    Extjs - A smart registry to find objects easy

    JavaScript 6 views posted 8 years ago by jvandemerwe
  18. FAV

    OOJS - Compare Execution Time of Both Approaches

    JavaScript 3 views posted 8 years ago by reelfernandes
  19. FAV

    OOJS - Object Oriented Javascript pt 2

    using prototype to add instance methods to a Class
    JavaScript 4 views posted 8 years ago by reelfernandes
  20. FAV

    OOJS - Object Oriented Javascript

    JavaScript 4 views posted 8 years ago by reelfernandes
  21. FAV

    Javascript revealing module pattern template

    "Javascript module pattern emulates the concept of classes in such a way that we're able to include both public/private methods and variables inside a single object, thus shielding/namespacing particular parts from the global scope." When inheritanc...
    JavaScript 6 views posted 8 years ago by coprolit
  22. FAV

    Checking Object Properties

    http://blog.ramonlechuga.com/2010/10/20/checking-object-structure/ The Array
    JavaScript 1 views posted 8 years ago by ramonlechuga
  23. FAV

    JS Object Tmplate

    JavaScript 4 views posted 9 years ago by loric
  24. FAV

    SimpleAjax Object

    Simple ajax object for creating ajax calls. Why use SimpleAjax? - Very small, only 2kb minified - Make a asynchrone or synchrone ajax call ( AJAX / SJAX ) - Use quick methods get() and post() for GET and POST calls - Use load() method for...
    JavaScript 5 views posted 9 years ago by freelancephp
  25. FAV

    getting an objects key values

    I wanted to pass a form submission (array) as a JSON object to another function. Some form field were created with JS, to identify them their names have been concatenated with unique IDs, etc. In order to access values of that JSON obj I needed to...
    JavaScript saved by 4 people 6 views posted 9 years ago by iroybot
  26. FAV

    getting an objects key values

    I wanted to pass a form submission (array) as a JSON object to another function. Some form field were created with JS, to identify them their names have been concatenated with unique IDs, etc. In order to access values of that JSON obj I needed to...
    JavaScript 5 views posted 9 years ago by iroybot
  27. FAV

    Object Literal Architecture Template

    Template for a Object Literal Architecture in javascript, in this case jQuery
    JavaScript 4 views posted 9 years ago by athanassiadis
  28. FAV

    Array to SELECT

    This function automates the creation of the <OPTION>s of a <SELECT> element. It's ideal for your AJAX apps when you create display elements using Javascript It accepts to different kind of arrays: An array of key:values… var arrDirs = {...
    JavaScript 5 views posted 9 years ago by nomada
  29. FAV

    Object Reflections

    this is my way of working out the contents of an object when I don't have access to a debugger like firebug
    JavaScript 4 views posted 9 years ago by iancrowther
  30. FAV

    Check if object exists

    JavaScript 3 views posted 9 years ago by dmistriotis
« Prev 1 2 3