([1,2,3]).draw()
[1,2,3].draw()
Array.prototype.draw = function(){ console.log(this) };
var myDataObject = {}
, dataExample1 = { sip:"1.1.1.1:11233", title:"block", value:"val 1"}
, dataExample2 = { sip:"1.1.1.1:11233", title:"block", value:"val 2"}
, dataExample3 = { sip:"1.1.1.1:11233", title:"view", value:"val 3"}
;
addMyData = function(data){
var exData = myDataObject[data.sip]
, exTitle
;
if( !exData ){
exData = myDataObject[data.sip] = { title: {} }
}
exTitle = exData.title[data.title];
if( !exTitle ){
exTitle = exData.title[data.title] = []
}
exTitle.push( data.value );
}
addMyData(dataExample1);
addMyData(dataExample2);
addMyData(dataExample3);
console.log(myDataObject);
console.info(JSON.stringify(myDataObject, null, 4));
prompt("Please enter your name", "Harry Potter");
class bgViewer
dn = (e) ->
@isStop = false
@sx = @lx = e.pageX or (e.originalEvent and e.originalEvent.touches and e.originalEvent.touches[0] and e.originalEvent.touches[0].pageX) or 0
@sy = @ly = e.pageY or (e.originalEvent and e.originalEvent.touches and e.originalEvent.touches[0] and e.originalEvent.touches[0].pageY) or 0
return false
up = (e) ->
@isStop = true
return false
move = (e) ->
if @isStop then return
x = e.pageX or (e.originalEvent and e.originalEvent.touches and e.originalEvent.touches[0] and e.originalEvent.touches[0].pageX) or 0
y = e.pageY or (e.originalEvent and e.originalEvent.touches and e.originalEvent.touches[0] and e.originalEvent.touches[0].pageY) or 0
dx = x - @lx
dy = y - @ly
if Math.abs(x-@sx) < @filter and Math.abs(y-@sy) < @filter
return
@lx = x
@ly = y
@x = (@x + dx) % @w
@y = (@y + dy) % @h
@cnt.css(
'background-position': @x + 'px ' + @y + 'px'
)
return false
free: ->
@cnt.off( 'mousedown touchstart', @dnxt
).off( 'mouseup touchend', @upxt
).off( 'mousemove touchmove', @movext )
return @
url: (src) ->
@src = src
@img = new Image
@img.src = src
$( @img ).on( 'load', (e) =>
@w = @img.width
@h = @img.height
)
@cnt.css(
'background-image': 'url(' + src + ')'
'background-position': '0px 0px'
)
@x = 0
@y = 0
@lx = 0
@ly = 0
@sx = 0
@sx = 0
return @
constructor: (@cnt, @src = '', @filter = 5) ->
@cnt.css(
'overflow': 'hidden'
'background-repeat': 'repeat'
'background-position': '0px 0px'
'cursor': 'move'
)
@x = 0
@y = 0
@lx = 0
@ly = 0
@sx = 0
@sx = 0
@isStop = true
t = @
@dnxt = (e) -> dn.call t, e
@upxt = (e) -> up.call t, e
@movext = (e) -> move.call t, e
@cnt.on( 'mousedown touchstart', @dnxt
).on( 'mouseup touchend', @upxt
).on( 'mousemove touchmove', @movext )
@cnt[0].bgviewer = @
@url @src
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="lib/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="app/bgviewer.js"></script>
<style>
BODY {
padding: 0;
margin: 0;
left: 0;
top: 0;
right: 0;
bottom: 0;
overflow: hidden;
position: absolute;
}
.viewer {
width: 100%;
height: 100%;
background-color: #434343;
}
</style>
</head>
<body>
<div class="viewer" id="viewer"></div>
<script type="text/javascript">
$(function(){
window.t2 = new bgViewer(
$('#viewer'),
'image.jpg',
10 // Filter motion less 10 px
);
});
</script>
</body>
</html>
var str = "1234567890";
var num = 1234567890;
console.log( 'From string:', parseInt(str).toLocaleString('ru-RU') );
console.log( 'From number:', num.toLocaleString('ru-RU') );
"1 234 567 890"
"1 234 567 890"
Кэш процессора Кэш микропроцессора — кэш (сверхоперативная память), используемый микропроцессором компьютера для уменьшения среднего времени доступа к компьютерной памяти. Является одним из верхних уровней иерархии памяти. Кэш использует небольшую, очень быструю память (обычно типа SRAM), которая хранит копии часто используемых данных из основной памяти.
var t = Object.prototype.toString;
function isArray (s) { return t.call(s) === '[object Array]'; };
var x = [1,2,3];
if( isArray(x) && x.length > 0 ){ console.log('x is array and length is', x.length)} else { console.log('x isnt array') }
var x = {};
if( isArray(x) && x.length > 0 ){ console.log('x is array and length is', x.length)} else { console.log('x isnt array') }