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 3451 posted 8 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 958 posted 8 years ago by BrentS
A template for a javascript object with a object.create shiv to condense into object prototypes
0 714 posted 9 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 693 posted 9 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 753 posted 10 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 1124 posted 11 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 897 posted 11 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 672 posted 12 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 637 posted 12 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 811 posted 12 years ago by coprolit
an operator that implements true prototypal Object inheritance in JavaScript
0 601 posted 12 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 1651 posted 12 years ago by claudiowebdesign
Using an object as a simple switch.
0 717 posted 12 years ago by 1man
using prototype to add instance methods to a Class
0 669 posted 13 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 706 posted 13 years ago by coprolit
http://blog.ramonlechuga.com/2010/10/20/checking-object-structure/ The Array
0 471 posted 13 years ago by ramonlechuga
0 482 posted 13 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 574 posted 13 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 631 posted 13 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 746 posted 13 years ago by iroybot
Template for a Object Literal Architecture in javascript, in this case jQuery
0 522 posted 13 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 506 posted 13 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 409 posted 13 years ago by iancrowther
0 631 posted 13 years ago by dmistriotis
pass in 2 json objects returns an array of all differences included those nested in children. _Q used internally to pass through to self, do not pass in _Q
0 810 posted 13 years ago by tennison
« Prev 1 2 3