Welcome To Snipplr


Everyone's Recent JavaScript Snippets Tagged object



« Prev 1 2 3
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)....
0 604 posted 4 years ago by Balamir
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,...
0 162 posted 5 years ago by BrentS
A template for a javascript object with a object.create shiv to condense into object prototypes
0 114 posted 6 years ago by rickygri
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.
0 115 posted 6 years ago by apphp-snippets
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...
1 132 posted 6 years ago by rickygri
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...
0 167 posted 7 years ago by davidwaterston
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...
0 143 posted 7 years ago by halk
`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.
0 90 posted 8 years ago by EvanHahn
Function to validate the existence of each key in the object to get the number of valid key/value pairs.
0 98 posted 8 years ago by reverend
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...
0 138 posted 8 years ago by coprolit
an operator that implements true prototypal Object inheritance in JavaScript
0 94 posted 8 years ago by luizlopes
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:...
0 228 posted 8 years ago by claudiowebdesign
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.
0 125 posted 9 years ago by supermauerbros
Using an object as a simple switch.
0 110 posted 9 years ago by 1man
using prototype to add instance methods to a Class
0 81 posted 9 years ago by reelfernandes
"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...
0 96 posted 9 years ago by coprolit
http://blog.ramonlechuga.com/2010/10/20/checking-object-structure/ The Array
0 85 posted 9 years ago by ramonlechuga
0 61 posted 9 years ago by loric
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...
0 89 posted 9 years ago by freelancephp
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...
1 96 posted 9 years ago by iroybot
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...
0 97 posted 9 years ago by iroybot
Template for a Object Literal Architecture in javascript, in this case jQuery
0 80 posted 9 years ago by athanassiadis
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 = {...
0 80 posted 9 years ago by nomada
this is my way of working out the contents of an object when I don't have access to a debugger like firebug
0 49 posted 9 years ago by iancrowther
« Prev 1 2 3