Welcome To Snipplr
Everyone's Recent JavaScript Snippets Tagged object
- All /
- JavaScript /
- HTML /
- PHP /
- CSS /
- Ruby /
- Objective C
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
2751
posted 7 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
747
posted 7 years ago by BrentS
A template for a javascript object with a object.create shiv to condense into object prototypes
0
566
posted 8 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
553
posted 8 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
568
posted 9 years ago by rickygri
JavaScript
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...
0
859
posted 10 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
728
posted 10 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
531
posted 11 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
501
posted 11 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
663
posted 11 years ago by coprolit
an operator that implements true prototypal Object inheritance in JavaScript
0
467
posted 11 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
1353
posted 11 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
624
posted 11 years ago by supermauerbros
"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
561
posted 12 years ago by coprolit
http://blog.ramonlechuga.com/2010/10/20/checking-object-structure/
The Array
0
373
posted 12 years ago by ramonlechuga
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
442
posted 12 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
483
posted 12 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
591
posted 12 years ago by iroybot
Template for a Object Literal Architecture in javascript, in this case jQuery
0
401
posted 12 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
413
posted 12 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
311
posted 12 years ago by iancrowther