Skip to content

Instantly share code, notes, and snippets.

@iArnaud
iArnaud / script.js
Created March 25, 2014 09:17
Javascript recursively copy two object literals
Source: http://stackoverflow.com/questions/20101788/why-does-jquery-extend-fail-to-recursively-copy-these-two-object-literals/20102047#20102047
$.extend is not meant to be used this way.
However you can write your own extend/merge function. Here's an example of a function that will merge every objects considered equal (based on the value of a specific key) from multiple provided arrays together.
The following merge algorithm will override primitive values and will concatenate arrays. The initial arrays and their objects aren't modified.
It's probably overkill if you only have to do this once, however it's an example on how you could implement your own encapsulated merging algorithm.
/**
* Lucida Grande doesn't have italics, but is preferable for its small size awesomeness.
* Lucida Sans has lovely italics.
* Let's use @font-face to combine them
*/
body {
font-family:'Lucida Improved','Lucida Grande','Lucida Sans','Lucida Sans Unicode',Verdana,sans-serif;
}
@font-face {
font-family:'Lucida Improved';
<!DOCTYPE html>
<head>
<title>Stay Standalone</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script src="stay_standalone.js" type="text/javascript"></script>
</head>
<body>
<ul>
<li><a href="http://google.com/">Remote Link (Google)</a></li>
/**
* Provides requestAnimationFrame in a cross browser way.
* @author paulirish / http://paulirish.com/
*/
if ( !window.requestAnimationFrame ) {
var pollFocus;
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
<ul id="top-menu">
<li class="active">
<a href="#">Top</a>
</li>
<li>
<a href="#foo">Foo</a>
</li>
<li>
<a href="#bar">Bar</a>
</li>
<ul id="top-menu">
<li class="active">
<a href="#">Top</a>
</li>
<li>
<a href="#foo">Foo</a>
</li>
<li>
<a href="#bar">Bar</a>
</li>
//
// UIControls.m
// PhoneGap
//
// Created by Michael Nachbaur on 13/04/09.
// Copyright 2009 Decaf Ninja Software. All rights reserved.
//
#import "UIControls.h"
@mixin rgba-background($color, $opacity) {
background-color: $color;
background-color: rgba($color, $opacity);
background-color: transparent\9;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#{'#'+hex(round($opacity*255)) + '' + hex(red($color)) + '' + hex(green($color)) + '' + hex(blue($color))},endColorstr=#{'#'+hex(round($opacity*255)) + '' + hex(red($color)) + '' + hex(green($color)) + '' + hex(blue($color))});
zoom: 1;
}
/* iOS Native App Default Style implemented in CSS */
/* Bootstrapping … */
* {
margin: 0;
padding: 0;
font-size: inherit;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}