what is by mean an instance? or instance of?

user3057928

I am struggling with the keyword 'instance'. In Java, I only know how to create the "new" keyword. Now, I'm learning about JavaScript, some author heavily used the word 'instance':

function Foo(){}

var foo = new Foo();

//foo is now an instance of Foo
console.log(foo instanceof Foo ) //=> true

What is the purpose of making foo instanceof Foo?

Satheesh Cheveri

instanceof is a binary operator, The instanceof allows to check if the object is created by given constructor:

The instanceof operator returns true if object is an instance of class. It returns true if true if class is present in the object's prototype chain. It returns false if object is not an instance of class, or if object is null.

function Rabbit() { }
var rabbit = new Rabbit

alert(rabbit instanceof Rabbit) // true

In the example above, the match is found at the first step, because: rabbit.proto == Rabbit.prototype.

Few helpful links

What is the instanceof operator in JavaScript?

http://www.w3schools.com/js/js_objects.asp

http://javascript.info/tutorial/instanceof#the-instanceof-operator

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

what object type/instance to use for synchronization

来自分类Dev

LinkedHashMap的instance

来自分类Dev

LinkedHashMap的instance

来自分类Dev

null == instance而不是instance == null

来自分类Dev

Synchronised instance methods in java

来自分类Dev

Java枚举中的INSTANCE

来自分类Dev

重复的符号__instance

来自分类Dev

Java枚举中的INSTANCE

来自分类Dev

What object type is the instance element parameter pass into the link function of an angular directive?

来自分类Dev

Static function returning a static instance of the class - shouldn't the instance be the same?

来自分类Dev

Utility :: get_instance()应该与&Singleton :: get_instance()兼容

来自分类Dev

What does "& _" mean in VB?

来自分类Dev

Pass object instance to Roslyn ScriptEngine

来自分类Dev

Creating a new instance of another file

来自分类Dev

Mapping instance to object in Ninject bindings

来自分类Dev

Assert attribute on mock instance was accessed

来自分类Dev

Ember Model with only One Instance

来自分类Dev

Static Instance Base/Derived class

来自分类Dev

create an instance of class in python 2.7

来自分类Dev

Access class variable from instance

来自分类Dev

java.lang.NoSuchFieldError:INSTANCE

来自分类Dev

`instance_eval`和范围

来自分类Dev

Accessing the child AnchorPane of a Tab instance

来自分类Dev

xcode - unrecognized selector sent to instance

来自分类Dev

Problems decorating an instance method in JavaScript

来自分类Dev

Cartrige instance.yml文件

来自分类Dev

HibernateUtil中的INSTANCE是什么?

来自分类Dev

ServiceStackHost.Instance已设置

来自分类Dev

any_instance与实例无关