---
title: "extjs mixin example"
author: "standalone"
date: "2012-11-14T17:29:06Z"
tags: []
categories: ["编程语言"]
slug: "extjs-mixin-example"
draft: false
lastmod: "2012-11-14T17:30:35Z"
id: 1725697
url: "https://standalone.iteye.com/blog/1725697"
---

```javascript

//1. Define our simple mixin class called HasCamera with a single //method called takePhoto:
Ext.define('HasCamera', {
takePhoto: function(){
alert('Say Cheese! .... Click!');
}
});
//2. Define a skeleton class and use the mixins configuration option //to apply our HasCamera mixin to our Cookbook.Smartphone class.
Ext.define('Cookbook.Smartphone', {
mixins: {
camera: 'HasCamera'
}
});
//3. We can now call our mixin's takePhoto method as part of the 
// Smartphone's class within a useCamera method:
Ext.define('Cookbook.Smartphone', {
mixins: {
camera: 'HasCamera'
},
useCamera: function(){
this.takePhoto();
}
});
//4. Instantiate the Smartphone class and call the useCamera method:
var smartphone = Ext.create('Cookbook.Smartphone');
smartphone.useCamera(); // alerts 'Say Cheese! .... Click!'

```