jkmiva / blog Goto Github PK
View Code? Open in Web Editor NEWnotes
notes
interface SquareConfig {
color?: string;
width?: number;
[propertyName: string]: any;
}
here we are saying a SquareConfig can have any number of properties, and as long as they are not color
or width
, their types don't matter.
interface StringArray {
[index: number]: string;
}
let myArray: StringArray;
myArray = ["Bob", "Fred"];
let myStr: string = myArray[0];
This index signature states that when a StringArray
is indexed with a number
, it will return a string
interface SearchFunc {
(source: string, subString: string): boolean;
}
let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
let result = source.search(subString);
return result > -1;
}
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
function getCounter(): Counter {
let counter = <Counter>function (start: number) { };
counter.interval = 123;
counter.reset = function () { };
return counter;
}
let c = getCounter();
c(10);
c.reset();
c.interval = 5.0;
an object that acts as both a function and an object, with additional properties
任何pod处于“健康”状态下(至少container要运行正常)即为 ready 状态
ready 状态持续了 minReadySeconds 以后就同时也是available状态。
That's to say, availableReplicas is any readyRelicas that last for at least minReadySeconds seconds.
ES7 contains only two new features.
Any proposal at stage 4 will be included in new release of ECMA-262
[1,2,3].includes(1) // return true
[1,2,3].includes(99) // return false
2 ** 3 === 8
var a float64 = 3.14
v := reflect.ValueOf(a)
v.SetFloat(5.6) // Error, will panic
This code does not work which means v is not settable.
Settability is a property of reflection object, the CatSet
method can check settability of a Value.
Settability is determined by whether the reflection object holds the original item. When we say
var a float64 = 3.14
v := reflect.ValueOf(a)
We pass a copy of a to reflect.Value
, so the Interface value created as the argument to
reflect.ValueOf
is a copy of a, not a itself.
The correct version:
var a float64 = 3.14
p := reflect.ValueOf(&a) // Note: take the address of a.
fmt.Println("type of p:", p.Type())
fmt.Println("settability of p:", p.CanSet()) // Note: p it self is a pointer copy, so p is not settable)
v := p.Elem() // get what p points to
fmt.Println("settability of v:", v.CanSet()) // print 'true'
v.SetFloat(7.1)
fmt.Println(v.Interface()) // print 7.1
fmt.Println(x) // print 7.1
Concerning a struct T, the fields name of T shoud be Uppercase(exported) because only exported
fields of a struct are settable
// at most three are running work at a time
var limit = make(chan int, 3)
func main() {
for _, w := range works {
go func(w func()) {
limit <- 1
w()
<- limit
}(w)
}
select{}
}
之前写的一个demo用proxy实现了简单的logger效果, 监听 构造函数(new) 和 send 方法
let WebSocketLogger = new Proxy(window.WebSocket,{
construct: function(target, args, recver) {
ret = Reflect.construct(target, args)
let oFn = e=>console.log('WSOpen: ', e)
let mFn = e=>console.log('WSMessage: ', e)
let cFn = e=>console.log('WSClose: ', e)
let eFn = e=>console.error('WSError: ', e)
ret.addEventListener('open',oFn)
ret.addEventListener('message',mFn)
ret.addEventListener('close',cFn)
ret.addEventListener('error',eFn)
let sendProxy = new Proxy(ret.send, {
apply: function(target, thisArg, args) {
console.log('[WSSending] ', ...args)
Reflect.apply(...arguments)
}
})
ret.send = sendProxy
return ret
}
})
Attributes are defined by HTML. Properties are defined by DOM.
Some HTML attributes have 1:1 mapping onto properties. id is one example of such.
Some do not (e.g. the value attribute specifies the initial value of an input, but the value property specifies the current value).
https://stackoverflow.com/questions/19246714/html-attributes-vs-properties
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.